shortMessageModule.controller("ShortMessageBatchEditCtrl", ["$log", "$scope", "$q", "$timeout", "$modalInstance", "dataDicSvc", "aresDialog", "aresNotification", "shortMessageBatchSvc", "shortMessageSvc", "formatUtil", "host", "$modal", "officeOptionSvc", "loginContext", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v, y) {
    "use strict";
    var p = {
            manualSend: !0
        },
        rt = function(n) {
            var t = [],
                i;
            return angular.forEach(n, function(n) {
                var i = _.find(t, function(t) {
                    return t.name == n.category
                });
                i || (i = {
                    name: n.category,
                    items: [],
                    spriteCssClass: "folder"
                }, t.push(i));
                n.spriteCssClass = "html";
                i.items.push(n)
            }), i = l.apptId > 0, i || (t = _.reject(t, {
                name: "预约"
            })), t
        },
        ut = function(n) {
            var i = !_.isUndefined(n.id);
            i && (p.shortMessageTemplateId = n.id, t.selectedTemplate = n, ft(n))
        },
        ft = function(n) {
            n.content || (n.content = "");
            var i = angular.copy(n.content);
            (t.shortMessageSignature && (i = "【" + t.shortMessageSignature + "】" + i), t.formatFields && t.formatFields.length != 0) && (t.formatFields.forEach(function(n) {
                var r = i.indexOf(n.key),
                    t;
                r > -1 && (t = new RegExp(n.key, "g"), i = i.replace(t, n.value))
            }), n.type == 1 && (i += "退订回TD"), t.previewText = i)
        },
        ni = function(n) {
            t.templateId = n.id;
            h.generateMessage(n.id, l.patientId, l.apptId).success(function(n) {
                t.message = n
            })
        },
        et = function() {
            p.id && (t.pageIndex = 1, w())
        },
        ot = function(n) {
            t.pageIndex = n;
            w()
        },
        w = function() {
            s.getItems(p.id, t.pageIndex, t.pageSize).success(function(n) {
                t.itemPage = n;
                var i = st(n);
                t.patients = i
            })
        },
        st = function(n) {
            var t = _.map(n.items, function(n) {
                var t = n.patient;
                return t.status = n.status, t
            });
            return c.formatPatients(t, {
                birth: "ageStr",
                status: "shortMessageStatus"
            }), t
        },
        d = function(n) {
            var n = _.each(n, function(n) {
                n.status = 0
            });
            return c.formatPatients(n, {
                birth: "ageStr",
                status: "shortMessageStatus"
            }), n
        },
        ht = function(n) {
            s.get(n).success(function(n) {
                tt(n);
                et();
                n.shortMessageTemplateId && r(function() {
                    t.selectTemplate(n.shortMessageTemplateId)
                }, 400)
            })
        },
        ct = function() {
            f.shortMessageTemplateDic.loadActive().then(function(n) {
                if (t.templates = n, t.categories = rt(n), l.batchId && ht(l.batchId), t.criteria) t.patients = d(l.patients), t.itemPage = {
                    totalCount: t.patientCount
                };
                else if (l.patients && l.patients.length > 0) {
                    t.patients = d(l.patients);
                    var i = _.pluck(t.patients, "id");
                    nt().then(function() {
                        gt(i).then(function() {
                            w()
                        })
                    })
                }
            });
            t.action = l.action || (l.batchId ? "edit" : "add");
            t.isViewMode = t.action == "view";
            lt().then(function() {
                at()
            })
        },
        lt = function() {
            var n = i.defer(),
                r = f.officeInfoDic.load().then(function(n) {
                    t.officeInfo = n
                }),
                u = v.getOfficeOption(v.optionKeys.ShortMessageSignature).then(function(n) {
                    if (t.shortMessageSignature = n, !t.shortMessageSignature || t.shortMessageSignature.length == 0) {
                        var i = f.officeDic.getItemSync(y.officeId);
                        i && (t.shortMessageSignature = i.abbreviation)
                    }
                });
            return i.all([r, u]).then(function() {
                n.resolve()
            }), n.promise
        },
        at = function() {
            t.formatFields = [{
                key: "【患者姓名】",
                value: "xxx"
            }, {
                key: "【病人姓名】",
                value: "xxx"
            }, {
                key: "【患者称呼】",
                value: "xx"
            }, {
                key: "【预约时间】",
                value: "xxxx年xx月xx日 xx:xx"
            }, {
                key: "【预约医生】",
                value: "xxx"
            }, {
                key: "【ApptTime】",
                value: "xxxx年xx月xx日 xx:xx"
            }, {
                key: "【诊所名称】",
                value: t.officeInfo.name
            }, {
                key: "【诊所地址】",
                value: t.officeInfo.address
            }, {
                key: "【诊所电话】",
                value: t.officeInfo.phoneNumber
            }, ]
        },
        vt = function() {
            Ares.ensureNotDuplicated("SaveShortMessageBatch") && g().then(function(n) {
                o.success("保存成功");
                k(n)
            })
        },
        g = function(n) {
            var u = i.defer(),
                f, r;
            return t.validate() && (t.criteria ? (f = {
                providerId: y.providerId,
                criteria: t.criteria.filter,
                isSearchPatientByDB: t.criteria.isSearchPatientByDB,
                hasMobile: !0,
                isSend: n,
                ignoreDay: t.ignoreDay,
                shortMessageTemplateId: p.shortMessageTemplateId
            }, s.saveShortMessageBatchAsync(f).success(function() {
                e.info("提示", "成功加入发送队列，请稍后前往短信中心查看发送状态");
                k({
                    itemCount: t.patientCount
                });
                u.reject()
            })) : (r = b(), r.id ? (r.isTemporary && (r.isTemporary = !1), s.update(r).success(function(n) {
                n.itemCount = t.itemPage.totalCount;
                u.resolve(n)
            })) : s.add(r).success(function(n) {
                n.itemCount = t.itemPage.totalCount;
                u.resolve(n)
            }))), u.promise
        },
        nt = function() {
            var r = i.defer(),
                t = b();
            return t.id ? n.error("short message batch already saved.") : (t.isTemporary = !0, s.add(t).success(function(n) {
                tt(n);
                r.resolve(n)
            })), r.promise
        },
        ti = function() {
            var n = i.defer();
            return h.validMessage(t.selectedTemplate.content).success(function(t) {
                n.resolve(t)
            }).error(function(t) {
                t && t.name == "AresMessageInvalidException" && e.warn("错误", "消息内容" + t.message);
                n.resolve(!1)
            }), n.promise
        },
        yt = function() {
            var n;
            if (Ares.ensureNotDuplicated("SendShortMessageBatch")) {
                if (n = t.patients && t.patients.length > 0, !n) {
                    e.info("提示", "没有收件人，不能发送！");
                    return
                }
                if (!t.selectedTemplate) {
                    e.info("提示", "请选择模板");
                    return
                }
                var f = b(),
                    i = t.previewText.length,
                    r = window.Ares.getShortMessageCount(i),
                    u = r * t.itemPage.totalCount;
                e.confirm("短信群发确认", "短信内容过长时，系统会自动切分为多条发送并计费。大约发送" + u + "条，是否确认发送？").then(function() {
                    p.status && p.status != 0 ? p.status == 1 ? e.info("提示", "该群发已经进入发送队列，等待发送！") : e.info("提示", "该群发已发送！") : g(!0).then(function(n) {
                        s.send(n.id).success(function() {
                            k(n);
                            e.info("提示", "成功加入待发送队列，预计将在10分钟内开始发送，请稍后查看发送状态。")
                        }).error(function(n) {
                            n.name == "ShortMessageAccountException" && e.warn("错误", n.message)
                        })
                    })
                })
            }
        },
        tt = function(n) {
            _.extend(p, n);
            p.manualSend = !n.scheduleTime;
            t.ignoreDay = n.ignoreDay || n.ignoreDay == 0 ? parseInt(n.ignoreDay) : null;
            n.manualSend || (p.scheduleTime = moment(n.scheduleTime).toDate())
        },
        b = function() {
            var n = _.clone(p);
            return n.ignoreDay = t.ignoreDay ? parseInt(t.ignoreDay) : null, n.manualSend ? n.scheduleTime = null : n.scheduleTime && (n.scheduleTime = moment(n.scheduleTime).format("YYYY-MM-DD")), n
        },
        k = function(n) {
            u.close(n)
        },
        pt = function() {
            p.isTemporary && (s.destroy(p.id), n.info("destroy temporary batch"));
            !p.isTemporary && t.hasChanged ? u.close(p) : u.dismiss("cancel")
        },
        wt = function(n) {
            var i = {
                batchId: p.id,
                patientId: n
            };
            s.delByPatientId(i).success(function() {
                w();
                t.hasChanged = !0
            })
        },
        bt = function() {
            p.id ? it(p.id) : nt().then(function(n) {
                it(n.id)
            })
        },
        it = function(n) {
            var i = t.patients ? t.patients.length : 0,
                r = a.open({
                    animation: !0,
                    backdrop: "static",
                    template: "<short-message-search-patient-view><\/short-message-search-patient-view>",
                    controller: "ShortMessageSearchPatientCtrl",
                    size: "lg",
                    windowClass: "xl-dialog",
                    resolve: {
                        host: function() {
                            return {
                                id: n,
                                patientCount: i
                            }
                        }
                    }
                });
            r.result.then(function(n) {
                t.hasChanged = n;
                n && w()
            })
        },
        kt = function(n) {
            var i = n.sender,
                r = i.value();
            (r || r == 0) && (t.ignoreDay = parseInt(i.value()), i.value(t.ignoreDay))
        },
        dt = function() {
            h.getShortRemainedCount().success(function(n) {
                t.needWarn = n <= 500;
                t.remainedCount = n
            })
        },
        gt = function(n) {
            var r = i.defer(),
                t, f, u;
            return n.length <= 0 && (e.info("信息", "请选择要添加的患者！"), r.reject()), t = [], angular.forEach(n, function(n) {
                var i = {
                    batchId: p.id,
                    patientId: n
                };
                t.push(i)
            }), f = t.length, u = {
                shortMessageBatchItems: t
            }, s.batchAdd(u).success(function() {
                r.resolve()
            }), r.promise
        };
    (function() {
        t.ignoreDay = 1;
        t.pageIndex = 1;
        t.pageSize = 15;
        t.maxPageCount = 5;
        t.shortMessageBatch = p;
        t.onItemPageChanged = ot;
        t.onTemlateChanged = ut;
        t.checkIsTemporarily = bt;
        t.ok = vt;
        t.cancel = pt;
        t.send = yt;
        t.delPatient = wt;
        t.onIgnoreDayChange = kt;
        t.criteria = l.criteria;
        t.patientCount = l.patientCount;
        ct();
        dt()
    })()
}]);
shortMessageModule.controller("ShortMessageBatchListCtrl", ["$log", "$scope", "$q", "$modal", "$filter", "shortMessageBatchSvc", "formatUtil", "aresNotification", function(n, t, i, r, u, f, e) {
    "use strict";
    var l = u("toShortMessageBatchStatusString"),
        o = function(n) {
            f.getAll().success(function(i) {
                a(i);
                t.batches = i;
                n && n()
            })
        },
        a = function(n) {
            e.formatList(n, {
                recordCreatedTime: "date",
                sendTime: "dateTime"
            }, function(n) {
                n.statusStr = l(n.status)
            })
        },
        v = function() {
            s().then(function(n) {
                c(n)
            })
        },
        h = function(n) {
            s(n).then(function(n) {
                c(n)
            })
        },
        y = function() {
            t.selectedItem && f.copy(t.selectedItem.id).success(function(n) {
                h(n.id)
            })
        },
        p = function(n) {
            var i = _.filter(t.batches, {
                id: parseInt(n)
            });
            s(n, "view", i[0].templateCategory)
        },
        c = function(n) {
            t.selectedItem = n;
            o()
        },
        w = function() {
            t.batches = [];
            o()
        },
        s = function(n, t, i) {
            var u;
            return u = i === "预约" ? r.open({
                animation: !0,
                backdrop: "static",
                template: "<short-message-appointment-edit-view><\/short-message-appointment-edit-view>",
                controller: "ShortMessageAppointmentEditCtrl",
                size: "lg",
                windowClass: "xl-dialog",
                resolve: {
                    host: function() {
                        return {
                            batchId: n || null,
                            action: t || null
                        }
                    }
                }
            }) : r.open({
                animation: !0,
                backdrop: "static",
                template: "<short-message-batch-edit-view><\/short-message-batch-edit-view>",
                controller: "ShortMessageBatchEditCtrl",
                size: "lg",
                windowClass: "xl-dialog",
                resolve: {
                    host: function() {
                        return {
                            batchId: n || null,
                            action: t || null
                        }
                    }
                }
            }), u.result
        };
    (function() {
        t.createBatch = v;
        t.editBatch = h;
        t.viewBatch = p;
        t.copyBatch = y;
        t.refresh = w;
        o()
    })()
}]);
shortMessageModule.controller("ShortMessageBatchPatientCtrl", ["$log", "$scope", "shortMessageBatchSvc", "$modalInstance", "patientSvc", "practiceSvc", "dataDicSvc", "host", "formatUtil", "aresDialog", "aresNotification", function(n, t, i, r, u, f, e, o, s, h, c) {
    "use strict";
    var v = function() {
            var n = Ares.today(),
                i = moment(n).startOf("month").toDate(),
                r = {
                    startDate: i,
                    endDate: n
                };
            t.dateRange = r
        },
        y = function() {
            e.doctorDic.loadActive().then(function(n) {
                t.Doctors = n
            })
        },
        p = function() {
            e.sourceTypeDic.loadActive().then(function(n) {
                t.patientSources = n
            })
        },
        w = function() {
            e.membershipTypeDic.loadActive().then(function(n) {
                t.membershipClass = n
            })
        },
        b = function() {
            v();
            y();
            p();
            w()
        },
        k = function(n) {
            var r = {
                batchId: o.id,
                patientId: n
            };
            i.addItem(r).success(function() {
                t.hasChange = !0;
                c.success("添加成功")
            })
        },
        d = function() {
            if (t.addPatientIds.length <= 0) {
                h.info("信息", "请选择要添加的患者！");
                return
            }
            l(t.addPatientIds)
        },
        g = function() {
            if (t.patients.length <= 0) {
                h.info("提示", "没有要添加的患者！");
                return
            }
            var n = t.getCriteria();
            u.getSearchPatientsNotPage(n).success(function(n) {
                if (n.length > 0)
                    if (n.length > 500) h.info("提示", "最多添加500个患者！当前搜索结果为：" + addPatients.length);
                    else {
                        var t = _.pluck(n, "id");
                        l(t)
                    }
            })
        },
        l = function(n) {
            angular.forEach(n, function(n) {
                var i = {
                    batchId: o.id,
                    patientId: n
                };
                t.shortMessageBatchItems.push(i)
            });
            var r = {
                shortMessageBatchItems: t.shortMessageBatchItems
            };
            i.batchAdd(r).success(function() {
                t.hasChange = !0;
                c.success("添加成功");
                a()
            })
        },
        a = function() {
            r.close(t.hasChange)
        },
        nt = function() {
            var n = t.getCriteria();
            u.getSearchPatientsEx(n).success(function(n) {
                t.searchResult = n;
                t.patients = t.searchResult.items;
                s.formatPatients(t.patients, {
                    birth: "ageStr",
                    status: "shortMessageStatus"
                });
                angular.forEach(t.patients, function(n) {
                    if (n.membershipId) {
                        var i = _.find(t.membershipClass, function(t) {
                            return t.id == n.membershipTypeId
                        });
                        n.membershipTypeName = i.name
                    }
                })
            })
        };
    (function() {
        t.hasChange = !1;
        t.onAdd = k;
        t.onBatchAdd = d;
        t.pageIndex = 1;
        t.cancel = a;
        t.search = nt;
        t.onAddAll = g;
        b()
    })()
}]);
shortMessageModule.controller("shortMessageBillOrderCtrl", ["$log", "$scope", "$q", "$filter", "shortMessageSvc", "$modal", "aresDialog", "aresNotification", function(n, t, i, r, u) {
    "use strict";
    var f, o = function() {
            var n = Ares.today(),
                i = moment(Ares.today()).startOf("month").toDate();
            f = {
                startDate: i,
                endDate: n
            };
            t.timeSpan = _.clone(f)
        },
        e = function() {
            var n = t.timeSpan.startDate || f.startDate,
                i = t.timeSpan.endDate || f.endDate;
            u.getBillOrder(n, i).success(function(n) {
                var i = s(n);
                t.billOrders = i
            })
        },
        s = function(n) {
            var t = 0;
            angular.forEach(n, function(i) {
                var u = r("toShortMessageBillOrderStatus"),
                    f = r("toInvoiceType");
                i.shortMessageBillOrderStatusStr = u(n.shortMessageBillOrderStatus);
                i.invoiceTypeStr = f(i.invoiceTypeStr);
                i.applyTime && (i.applyTime = moment(applyTime).format("YYYY-MM-DD hh:mm:ss"));
                i.billTime && (i.billTime = moment(applyTime).format("YYYY-MM-DD hh:mm:ss"));
                i.index = angular.copy(t);
                t += 1
            })
        };
    (function() {
        t.initData = e;
        o();
        e()
    })()
}]);
shortMessageModule.controller("ShortMessageChargeCtrl", ["$log", "$scope", "$modal", "$q", "shortMessageSvc", "loginContext", "officeSvc", "aresDialog", "bmsSvc", function(n, t, i, r, u, f, e, o) {
    "use strict";
    var h = function() {
            u.getChargeTransactions().success(function(n) {
                y(n);
                t.transactions = n
            })
        },
        y = function(n) {
            t.sumTransationsData.sumCount = 0;
            t.sumTransationsData.sumPrice = 0;
            t.sumTransationsData.sumPoint = 0;
            angular.forEach(n, function(n) {
                t.sumTransationsData.sumCount += n.transactionCount;
                t.sumTransationsData.sumPrice += n.price;
                t.sumTransationsData.sumPoint += n.point
            })
        },
        p = function() {
            u.getShortRemainedCount().success(function(n) {
                t.needWarn = n <= 500;
                t.remainedCount = n
            })
        },
        w = function() {
            e.getOfficePoint().then(function(n) {
                t.point = n.data
            })
        },
        c = function() {
            u.getOrdersByUser().success(function(n) {
                b(n);
                t.shortMessageOrders = n
            })
        },
        b = function(n) {
            angular.forEach(n, function(n) {
                n.payOrderNoStr = n.payOrderNo && n.payOrderNo.length > 14 ? n.payOrderNo.slice(0, 13) + "..." : n.payOrderNo
            })
        },
        s = function() {
            h();
            p();
            w();
            c()
        },
        l = function() {
            var n = r.defer();
            return u.checkPay(t.selectedPayType, t.payOrder.payOrderNo).success(function(t) {
                t && n.resolve({
                    result: t
                })
            }), n.promise
        },
        a = function() {
            l().then(function(n) {
                n && (s(), t.selectedPayType == "Ali" ? t.showNotification("支付宝付款成功！") : t.selectedPayType == "Weixin" && t.showNotification("微信付款成功！"))
            });
            h();
            c()
        },
        k = function(n) {
            var r = {
                    queryFunc: l,
                    interval: 5e3,
                    delay: 4e4,
                    maxCount: 20
                },
                u = i.open({
                    animation: !0,
                    backdrop: "static",
                    template: "<qrcode-dialog><\/qrcode-dialog>",
                    controller: "QrcodeDialogCtrl",
                    size: "sm",
                    resolve: {
                        host: function() {
                            return {
                                qrCode: n.payUrl,
                                outTradeNo: n.payOrderNo,
                                queryOption: r,
                                payChannel: t.selectedPayType
                            }
                        }
                    }
                });
            u.result.then(function(n) {
                n ? (s(), t.selectedPayType == "Ali" ? t.showNotification("支付宝付款成功！") : t.selectedPayType == "Weixin" && t.showNotification("微信付款成功！")) : a()
            }, function() {
                a()
            })
        },
        d = function() {
            if (Ares.ensureNotDuplicated("OnShortMessageCharged")) {
                if (t.clickCount == 0) {
                    t.showInfoNotification("请选择充值金额！");
                    return
                }
                if (t.selectedPayType == "") {
                    t.showInfoNotification("请选择支付方式！");
                    return
                }
                var n = {
                    payChannel: t.selectedPayType,
                    amount: v(t.clickCount),
                    count: g(t.clickCount),
                    point: v(t.clickCount)
                };
                if (t.selectedPayType == "Point") {
                    if (t.point < n.point) {
                        t.showErrorNotification("充值失败，诊所积分余额不足！");
                        return
                    }
                    u.chargeByPoint(n).success(function(n) {
                        if (n) {
                            s();
                            t.showNotification("充值成功！");
                            t.$emit("officePointChange", !0)
                        }
                    })
                } else t.selectedPayType == "Service" ? u.chargeByService(n).success(function(n) {
                    n && (s(), t.showNotification("提交成功！"))
                }) : u.beginPay(n).success(function(n) {
                    n && (t.payOrder = n, k(n))
                })
            }
        },
        v = function(n) {
            if (t.selectedPayType != "Point")
                if (Ares.isDebugEnabled()) switch (n) {
                    case "100":
                        return .01;
                    case "200":
                        return .02;
                    case "300":
                        return .03;
                    case "500":
                        return .04;
                    case "1000":
                        return .05
                } else switch (n) {
                    case "100":
                        return 100;
                    case "200":
                        return 200;
                    case "300":
                        return 300;
                    case "500":
                        return 500;
                    case "1000":
                        return 1e3
                } else switch (n) {
                    case "100":
                        return 1e3;
                    case "200":
                        return 2e3;
                    case "500":
                        return 5e3;
                    case "1000":
                        return 1e4
                }
        },
        g = function(n) {
            if (t.selectedPayType != "Point") switch (n) {
                case "100":
                    return 1250;
                case "200":
                    return 2500;
                case "300":
                    return 3750;
                case "500":
                    return 6250;
                case "1000":
                    return 12500;
                default:
                    return 0
            } else switch (n) {
                case "100":
                    return 125;
                case "200":
                    return 250;
                case "500":
                    return 625;
                case "1000":
                    return 1250;
                default:
                    return 0
            }
        },
        nt = function(n) {
            o.confirm("提示", "确认删除此订单么？").then(function() {
                u.deleteOrder(n).success(function(n) {
                    n && (t.showNotification("删除订单成功！"), s())
                })
            })
        },
        tt = function(n, t) {
            var i = {
                id: n,
                notes: t
            };
            u.updateOrderNotes(i).success(function() {})
        };
    (function() {
        t.point = 0;
        t.needWarn = !1;
        t.remainedCount = 0;
        t.sumTransationsData = {
            sumCount: 0,
            sumPrice: 0,
            sumPoint: 0
        };
        t.pay = d;
        t.deleteOrder = nt;
        t.updateOrderNotes = tt;
        s()
    })()
}]);
shortMessageModule.controller("ShortMessageConfigCtrl", ["$log", "$scope", "$q", "$timeout", "notificationSvc", "aresNotification", "enums", function(n, t, i, r, u, f, e) {
    "use strict";
    var o = function(n) {
            u.getAllRules().then(function(i) {
                var u = s(i.data, n);
                if (t.notificationRules = i.data, t.copyNotificationRules = angular.copy(i.data), _.isEmpty(i.data)) t.onAdd();
                else t.onSelectedRule(u);
                r(function() {
                    t.$apply()
                })
            })
        },
        s = function(n, t) {
            var i = {};
            return _.each(n, function(n) {
                n.ruleType === 1 && (n.showName = "会员生日送祝福");
                t && n.id == t && (n.selected = !0);
                i = n
            }), i
        },
        h = function(t) {
            t.id > 0 ? u.modifyRule(t).success(function() {
                o(t.id);
                f.success("保存成功")
            }).error(function(t) {
                n.log(t);
                f.error("保存失败")
            }) : u.createRule(t).success(function() {
                o();
                f.success("保存成功")
            }).error(function(t) {
                n.log(t);
                f.error("保存失败")
            })
        },
        c = function(n) {
            u.deleteRule(n).success(function() {
                o();
                f.success("删除成功")
            })
        },
        l = function() {
            return {
                id: 0,
                isEnable: !0,
                freqency: e.Frequency2.Daily,
                templateId: null,
                startTime: "00:00",
                ruleType: e.NotificationType.MembershipBirthday,
                dayOffSet: 0
            }
        };
    (function() {
        t.notificationRules = [];
        t.saveRule = h;
        t.deleteRule = c;
        t.createNewRuleObj = l;
        o()
    })()
}]);
shortMessageModule.controller("ShortMessageDashboardCtrl", ["$log", "$scope", "$q", "shortMessageSvc", function(n, t, i, r) {
    "use strict";
    var u = {},
        e = function() {
            var n = Ares.today(),
                t = moment(n).startOf("month").toDate(),
                i = {
                    startDate: t,
                    endDate: n
                };
            u.dateRange = i;
            u.statMode = "1"
        },
        o = function() {
            var n = i.defer();
            return r.getSummaryReport().success(function(i) {
                t.summaryData = i;
                n.resolve(i)
            }), n.promise
        },
        f = function() {
            var n = angular.copy(u);
            n.dateRange.endDate = moment(n.dateRange.endDate).add(1, "day").toDate();
            r.getTrendReport(n).success(function(n) {
                t.trendData = n;
                var i = n == null || n.length == 0;
                t.trendDataEmpty = i
            })
        },
        s = function() {
            o().then(function() {
                f()
            })
        },
        h = function() {
            c();
            f()
        },
        c = function() {
            var t = u.statMode,
                n;
            t == "2" ? (u.dateRange.startDate = moment(u.dateRange.startDate).day(1).toDate(), n = moment(u.dateRange.endDate), n.day() != 0 && (u.dateRange.endDate = n.day(7).toDate())) : t == "3" && (u.dateRange.startDate = moment(u.dateRange.startDate).date(1).toDate(), u.dateRange.endDate = moment(u.dateRange.endDate).date(1).add(1, "month").add(-1, "day").toDate())
        },
        l = function() {
            r.getShortRemainedCount().success(function(n) {
                t.needWarn = n <= 500;
                t.remainedCount = n
            })
        };
    (function() {
        t.criteria = u;
        t.search = h;
        e();
        s();
        l()
    })()
}]);
shortMessageModule.controller("shortMessageFeedbackCtrl", ["$log", "$q", "$scope", "shortMessageSvc", "formatUtil", "shortMessageUtil", function(n, t, i, r, u, f) {
    "use strict";
    var e = function() {
            var n = Ares.today(),
                t = moment(n).add(-1, "d").toDate();
            i.searchCriteria = {
                patientName: "",
                pageIndex: 1,
                pageSize: 10,
                mobile: "",
                startDate: t,
                endDate: n,
                dateType: 1
            }
        },
        o = function() {
            var n = t.defer();
            return r.searchFeedbackReport(i.searchCriteria).success(function(t) {
                s(t);
                n.resolve({
                    total: t.totalCount,
                    data: t.items
                })
            }), n.promise
        },
        s = function(n) {
            angular.forEach(n.items, function(n) {
                u.formatShortMessage(n)
            })
        },
        h = function(n) {
            r.getFeedbackSenderId(n).success(function(n) {
                f.sendMessage(n, -1)
            })
        };
    (function() {
        i.send = h;
        i.search = o;
        e()
    })()
}]);
shortMessageModule.controller("ShortMessageHistoryCtrl", ["$log", "$q", "$scope", "dataDicSvc", "enums", "shortMessageSvc", "formatUtil", "shortMessageUtil", "$state", "aresNotification", function(n, t, i, r, u, f, e, o, s, h) {
    "use strict";
    i.statusList = [u.ShortMessageStatus.Sending, u.ShortMessageStatus.Succeeded, u.ShortMessageStatus.Failed, u.ShortMessageStatus.Unknown, ];
    var c = function() {
            var t = Ares.today(),
                f = moment(t).add(-1, "d").toDate(),
                n = {
                    officeId: i.officeId,
                    startDate: f,
                    endDate: t,
                    patientName: null,
                    pageIndex: 1,
                    pageSize: 10
                },
                r, u;
            s.params.status == "发送失败" && (r = _.find(i.statusList, function(n) {
                return n.name == "发送失败"
            }), n.status = r.value);
            s.params.status == "发送成功" && (u = _.find(i.statusList, function(n) {
                return n.name == "发送成功"
            }), n.status = u.value);
            i.searchCriteria = n
        },
        l = function() {
            var n = t.defer();
            return !i.searchCriteria.startDate || i.searchCriteria.startDate < i.minDay ? h.error("只能查询18年之后的数据") : f.search(i.searchCriteria).success(function(t) {
                a(t);
                i.searchResult = t;
                n.resolve({
                    total: t.totalCount,
                    data: t.items
                })
            }), n.promise
        },
        a = function(n) {
            angular.forEach(n.items, function(n) {
                e.formatShortMessage(n)
            })
        },
        v = function(n) {
            o.resendMessage(n).then(function(t) {
                t && (i.selectedItem = _.find(i.searchResult, function(t) {
                    return t.id == n
                }))
            })
        },
        y = function(n) {
            f.getMessage(n).success(function(n) {
                var t = n.patientId;
                o.sendMessage(t, -1)
            })
        };
    (function() {
        c();
        i.search = l;
        i.resend = v;
        i.send = y
    })()
}]);
shortMessageModule.controller("ShortMessageSearchPatientCtrl", ["$log", "$scope", "$q", "shortMessageBatchSvc", "$modalInstance", "$modal", "patientSvc", "practiceSvc", "dataDicSvc", "host", "formatUtil", "aresDialog", "aresNotification", "patientUtil", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v) {
    "use strict";
    var y = function() {
            o.getSearchConfigAll().success(function(n) {
                var i, r;
                t.searchConfigs = n;
                t.isDoctor && (i = _.find(t.searchConfigs, function(n) {
                    return n.name == "全部患者" && n.id == 0
                }), i && i.isPreferred && (i.isPreferred = !1, r = _.find(t.searchConfigs, function(n) {
                    return n.name == "我的患者"
                }), r.isPreferred = !0))
            })
        },
        w = function() {
            var n = i.defer(),
                r;
            return t.searchConfig.orderByField = "p.Id", t.searchConfig.isAscending = !1, t.pageSize = t.pageSize ? parseInt(t.pageSize) : 10, r = {
                searchConfig: t.searchConfig,
                pageSize: t.pageSize,
                pageIndex: t.pageIndex,
                searchText: t.searchText
            }, e.selectBySearchConfig(r).success(function(i) {
                t.searchData = i;
                c.formatPatients(t.searchData.items, {
                    birth: "ageStr",
                    status: "patientStatus"
                });
                b();
                var r = {
                    total: t.searchData.totalCount,
                    data: t.searchData.items
                };
                v.formatPatientTagInfo(r.data).then(function() {
                    t.copyGridData = r;
                    n.resolve(r)
                })
            }).error(function(n) {
                n.name == "ContainsIllegalCharactersException" && l.error("提示", "查询失败,检查搜索条件有非法字符!")
            }), n.promise
        },
        b = function() {
            angular.forEach(t.searchData.items, function(n) {
                var i;
                n.marketCenterAccountStr = n.marketCenterAccount ? "已绑定" : "未绑定";
                n.mobile && (n.mobile = n.mobile.replace(",", "<br/>"), n.mobile = n.mobile.replace(",", "<br/>"));
                n.doctorName && (t.doctorData.length > 0 ? (i = _.find(t.doctorData, function(t) {
                    return t.id == n.doctorName
                }), n.doctorName = i ? i.name : "") : s.doctorDic.loadActive().then(function(i) {
                    t.doctorData = i;
                    var r = _.find(t.doctorData, function(t) {
                        return t.id == n.doctorName
                    });
                    n.doctorName = r ? r.name : ""
                }));
                n.lastDoctorName && (t.doctorData ? (i = _.find(t.doctorData, function(t) {
                    return t.id == n.lastDoctorId
                }), n.lastDoctorName = i ? i.name : "") : s.doctorDic.loadActive().then(function(i) {
                    t.doctorData = i;
                    var r = _.find(t.doctorData, function(t) {
                        return t.id == n.lastDoctorId
                    });
                    n.lastDoctorName = r ? r.name : ""
                }))
            })
        },
        k = function(n) {
            var i = null,
                r;
            n && (i = _.find(t.searchConfigs, function(t) {
                return t.id == n
            }));
            r = f.open({
                animation: !0,
                backdrop: "static",
                template: "<search-config-view><\/search-config-view>",
                controller: "SearchConfigCtrl",
                size: "lg",
                windowClass: "search-config-dialog",
                resolve: {
                    host: function() {
                        return {
                            searchConfig: i,
                            configNames: _.pluck(t.searchConfigs, "name")
                        }
                    }
                }
            });
            r.result.then(function(n) {
                var r = n,
                    i;
                n && (n.isDisposable ? n.id > 0 ? (i = _.find(t.searchConfigs, function(t) {
                    return t.id == n.id
                }), i && (i.isDisposable = !0, i.isShowWeiXin = n.isShowWeiXin), r = i, r.id = 0) : t.searchConfigs.push(n) : (n.name == "我的患者" || n.name == "全部患者" ? i = _.find(t.searchConfigs, function(t) {
                    return t.name == n.name
                }) : n.id > 0 && (i = _.find(t.searchConfigs, function(t) {
                    return t.id == n.id
                })), i ? (i.id = n.id, i.name = n.name, i.isAscending = n.isAscending, i.orderByField = n.orderByField, i.isShowWeiXin = n.isShowWeiXin, i.searchCondFields = n.searchCondFields, i.searchResultFields = n.searchResultFields) : t.searchConfigs.push(n)), t.initSearchConfigDropDown(r), t.search(!0))
            })
        },
        p = function() {
            u.close(t.hasChange)
        },
        d = function(n) {
            var i = {
                batchId: h.id,
                patientId: n
            };
            r.addItem(i).success(function() {
                t.hasChange = !0;
                a.success("添加成功")
            }).error(function(n) {
                if (n.name == "ShortMessageBatchItemOverageException") {
                    l.info("信息", "一次最多添加500个患者！");
                    return
                }
            })
        },
        g = function() {
            if (t.addPatientIds.length <= 0) {
                l.info("信息", "请选择要添加的患者！");
                return
            }
            t.shortMessageBatchItems = [];
            nt(t.addPatientIds)
        },
        nt = function(n) {
            angular.forEach(n, function(n) {
                var i = {
                    batchId: h.id,
                    patientId: n
                };
                t.shortMessageBatchItems.push(i)
            });
            var i = {
                shortMessageBatchItems: t.shortMessageBatchItems
            };
            r.batchAdd(i).success(function() {
                t.hasChange = !0;
                a.success("添加成功");
                p()
            })
        },
        tt = function() {
            s.doctorDic.loadActive().then(function(n) {
                it().then(function() {
                    rt().then(function() {
                        t.doctorData = n;
                        y()
                    })
                })
            })
        },
        it = function() {
            var n = i.defer();
            return s.consultantDic.loadActive().then(function(i) {
                t.consultantData = i;
                n.resolve(!0)
            }), n.promise
        },
        rt = function() {
            var n = i.defer();
            return o.getNationality().success(function(i) {
                t.nationalityData = i;
                n.resolve(!0)
            }), n.promise
        };
    (function() {
        t.initialize = !0;
        t.shortMessageBatchItems = [];
        t.openSearchConfigDialog = k;
        t.initSearchConfigs = y;
        t.hasChange = !1;
        t.onAdd = d;
        t.onBatchAdd = g;
        t.pageIndex = 1;
        t.pageSize = 10;
        t.cancel = p;
        t.initData = w;
        tt();
        t.$watch("pageSize", function() {
            t.pageSize === undefined && (t.pageSize = 500)
        })
    })()
}]);
shortMessageModule.controller("ShortMessageStatisticCtrl", ["$log", "$q", "$scope", "dataDicSvc", "enums", "shortMessageSvc", "formatUtil", "shortMessageUtil", "$state", "aresNotification", "officeSvc", "loginContext", "moduleOptionProvider", "officeSelectorUtil", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v) {
    "use strict";
    var p = function() {
            c.getSelfAndChildOfficesByGroupId(l.officeId, a.isDescendantDataOpen()).success(function(n) {
                i.officeTreeData = v.setId(n)
            })
        },
        w = function() {
            p()
        },
        b = function(n) {
            i.selectedOfficeIds = _.pluck(n, "officeId")
        },
        y = function(n) {
            var r = t.defer(),
                u = {
                    pageSize: i.pageSize,
                    pageIndex: n ? 1 : i.pageIndex,
                    officeIds: i.selectedOfficeIds,
                    startDate: i.startDate,
                    endDate: i.endDate,
                    isGroup: l.isGroup
                };
            return i.searchCriteria = u, r.resolve(u), r.promise
        },
        k = function(n) {
            var r = t.defer();
            return y(n).then(function(n) {
                f.getMessageStatistics(n).success(function(n) {
                    i.pageData = n;
                    r.resolve(i.pageData)
                })
            }), r.promise
        },
        d = function(n) {
            f.exportMessageStatistics(n)
        };
    (function() {
        i.pageSize = 20;
        i.pageIndex = 1;
        i.onOfficeSelected = b;
        i.refreshListData = k;
        i.initSearchCriteria = y;
        i.exportShortMessage = d;
        w()
    })()
}]);
shortMessageModule.controller("ShortMessageTemplateConfigCtrl", ["$log", "$q", "$scope", "officeUtil", "formatUtil", "shortMessageSvc", "aresDialog", "dataDicSvc", "officeOptionSvc", "permissionProvider", "moduleOptionProvider", "systemSettingItemSvc", "aresNotification", function(n, t, i, r, u, f, e, o, s, h, c, l, a) {
    "use strict";
    var p = function() {
            i.criteria || (i.criteria = {
                category: ""
            }, i.pageInfo = {
                pageSize: 15,
                pageIndex: 1
            })
        },
        v = function() {
            var n = t.defer(),
                r = angular.copy(i.criteria),
                u = r.category ? f.getShortMessageTemplateByCategory(r.category) : f.getAllActive();
            return u.then(function(t) {
                var r = t.data,
                    u, f;
                r = w(r);
                u = i.pageInfo.pageIndex == 1 ? 0 : (i.pageInfo.pageIndex - 1) * i.pageInfo.pageSize;
                f = u + i.pageInfo.pageSize;
                i.shortmessageTemplates = r.slice(u, f);
                i.pageInfo.totalCount = r.length;
                n.resolve()
            }), n.promise
        },
        y = function() {
            var n = t.defer();
            return v().then(function() {
                n.resolve()
            }), n.promise
        },
        w = function(n) {
            return n.forEach(function(n) {
                n.shortMessageTypeStr = n.type == "0" ? "行业" : n.type == "1" ? "营销" : "";
                n.recordCreatedTimeStr = moment(n.recordCreatedTime).format("YYYY-MM-DD HH:mm:ss")
            }), n
        },
        nt = function() {
            return y()
        },
        b = function(i) {
            var r = t.defer();
            return e.confirm("删除短信模板", "您确认要删除短信模板【" + i.name + "】吗？").then(function() {
                f.deleteTemplate(i.id).success(function() {
                    o.shortMessageTemplateDic.clearCache();
                    a.success("删除成功");
                    r.resolve()
                }).error(function(t) {
                    t.name === "EntityAlreadyUsedException" ? e.warn("提示", "该短信模板已经被使用，不能删除！") : (e.warn("提示", "该短信模板已经被使用，不能删除！"), n.error(t));
                    r.resolve()
                })
            }), r.promise
        },
        k = function() {
            var n = t.defer();
            return l.getItemTypes("短信大类").then(function(t) {
                i.templateCategories = t && t.data ? t.data : [];
                n.resolve()
            }), n.promise
        },
        d = function(r, u) {
            var f = t.defer();
            return e.confirm("删除短信模板", "您确认要删除短信类别【" + r.itemName + "】吗？").then(function() {
                l.destroySystemSettingItem(r.id).success(function() {
                    i.initCategoryList();
                    a.success("删除成功");
                    f.resolve()
                }).error(function(t) {
                    t.name === "EntityAlreadyUsedException" ? e.warn("提示", "该短信类别已经被使用，不能删除！") : n.error(t);
                    f.resolve()
                })
            }), u.stopPropagation(), f.promise
        },
        g = function(n) {
            var i = t.defer();
            return n.isDisabled = !n.isDisabled, f.updateTemplate(n).success(function() {
                o.shortMessageTemplateDic.refresh();
                a.success("保存成功");
                i.resolve()
            }).error(function(n) {
                i.reject();
                onError(n)
            }), i.promise
        };
    (function() {
        i.disableTemplate = g;
        i.destroy = b;
        i.load = y;
        i.searchShortmessageTemplates = v;
        i.initCategoryList = k;
        i.remove = d;
        i.initBaseInfo = p
    })()
}]);
shortMessageModule.directive("shortMessageTemplateCategoryEditView", ["$log", "$modal", "$timeout", "aresDialog", "enums", function(n, t, i) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        templateUrl: "/app/short-message/short-message-template-category-edit-dialog/short-message-template-category-edit-view.html",
        link: function(n, t) {
            var r = function() {
                t.parents(".modal-dialog").css("width", "300px");
                i(function() {
                    Ares.centerModal(t.closest(".modal-dialog"))
                }, 50)
            };
            (function() {
                r()
            })()
        }
    }
}]);
shortMessageModule.controller("shortMessageTemplateCategoryEditCtrl", ["$log", "$scope", "$modalInstance", "dataDicSvc", "practiceSvc", "host", "aresDialog", "expendSvc", "systemitemSvc", "systemSettingItemSvc", "aresNotification", function(n, t, i, r, u, f, e, o, s, h, c) {
    "use strict";
    var a = f.itemType;
    t.itemType = a;
    var v = function() {
            h.getItemTypes("短信大类").then(function(n) {
                t.templateCategories = n && n.data ? n.data : []
            })
        },
        y = function() {
            if (t.currentSystemSettingItem.itemName = t.currentSystemSettingItem.itemName.replace(/\s/g, ""), !t.currentSystemSettingItem.itemName) {
                e.warn("警告", "短信类别不能为空！");
                return
            }
            t.currentSystemSettingItem.id ? u.updateSystemSettingItem(t.currentSystemSettingItem).success(function(n) {
                c.success("保存成功");
                i.close(n)
            }).error(function(n) {
                n.name == "SystemSettingItemNameNotUniqueException" && (e.warn("警告", "已经有其他短信类别使用此名称，请更换新名称！"), l())
            }) : u.createSystemSettingItem(t.currentSystemSettingItem).success(function(n) {
                c.success("保存成功");
                i.close(n)
            }).error(function(n) {
                n.name == "SystemSettingItemNameNotUniqueException" && (e.warn("警告", "已经有短信类别使用此名称，请更换新名称！"), l())
            })
        },
        l = function() {
            v();
            t.systemsettingitemId > 0 ? u.GetSystemSettingItemById(t.systemsettingitemId).success(function(n) {
                t.currentSystemSettingItem = n
            }) : t.currentSystemSettingItem = {
                id: 0,
                itemName: "",
                itemType: "短信大类"
            }
        },
        p = function() {
            i.dismiss()
        };
    (function() {
        t.saveSystemSettingItem = y;
        t.cancel = p;
        t.systemsettingitemId = f.systemsettingitemId;
        t.title = f.systemsettingitemId ? "编辑短信类别" : "新建短信类别";
        l()
    })()
}]);
shortMessageModule.directive("shortMessageTemplateEditDialogView", ["$log", "$timeout", "systemSettingItemSvc", function(n, t, i) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        templateUrl: "/app/short-message/shortmessage-template-edit-dialog/short-message-template-edit-dialog-view.html",
        link: function(n, t) {
            var r = function() {
                    f()
                },
                f = function() {
                    i.getItemTypes("短信大类").then(function(i) {
                        var r = t.find("#category").kendoDropDownList({
                            dataSource: i,
                            dataTextField: "itemName",
                            dataValueField: "itemName",
                            value: n.template.category,
                            select: function(t) {
                                n.template.category = this.dataItem(t.item)[this.options.dataValueField] || null
                            }
                        })
                    })
                },
                e = function(n) {
                    var t = $("#category").data("kendoDropDownList");
                    t && (n.category = t.value())
                },
                o = function(i) {
                    var e;
                    i = "【" + i + "】";
                    var r = t.find(".comment-textarea")[0],
                        o = 0,
                        u = 0,
                        f = 0;
                    r.selectionStart && (o = r.selectionStart, u = r.selectionStart, f = r.selectionEnd);
                    e = r.value.substring(0, u) + i;
                    r.value = r.value.substring(0, u) + i + r.value.substring(f, r.value.length);
                    r.focus();
                    r.setSelectionRange(r.value.length, e.length);
                    n.template.content = r.value
                },
                u = function() {
                    n.templateLength = n.previewText ? n.previewText.length : 0;
                    n.messageCount = window.Ares.getShortMessageCount(n.templateLength)
                },
                s = function() {
                    n.formatMessageTemplate();
                    u()
                };
            (function() {
                n.initView = r;
                n.radioChange = s;
                n.setTemplateCategory = e;
                n.addTemplateContent = o;
                n.initTemplate().then(function() {
                    r()
                });
                n.$watch("template.content", function() {
                    n.template && (n.formatMessageTemplate(), u(n.template.content))
                }, !0)
            })()
        }
    }
}]);
shortMessageModule.controller("shortMessageTemplateEditDialogCtrl", ["$log", "$q", "$scope", "$filter", "formatUtil", "shortMessageSvc", "dataDicSvc", "$modalInstance", "host", "aresNotification", "officeOptionSvc", "loginContext", function(n, t, i, r, u, f, e, o, s, h, c, l) {
    "use strict";
    var p = function() {
            i.templateId = s.templateId;
            i.isBrowse = s.isBrowse
        },
        w = function() {
            var n = t.defer();
            return i.templateId ? f.getTemplate(i.templateId).then(function(t) {
                i.template = t.data;
                n.resolve()
            }) : (i.template = {
                type: 0,
                content: ""
            }, n.resolve()), n.promise
        },
        b = function() {
            return i.template.category ? i.template.name ? i.template.content ? !0 : (h.error("请输入短信内容"), !1) : (h.error("请输入短信名称"), !1) : (h.error("请输入短信类别"), !1)
        },
        k = function() {
            if (i.setTemplateCategory(i.template), b()) {
                var n = angular.copy(i.template);
                n.id ? f.updateTemplate(n).success(function(n) {
                    a(n)
                }).error(function(n) {
                    v(n)
                }) : f.addTemplate(n).success(function(n) {
                    a(n)
                }).error(function(n) {
                    v(n)
                })
            }
        },
        a = function(n) {
            e.shortMessageTemplateDic.clearCache();
            h.success("保存成功");
            o.close(n)
        },
        v = function(t) {
            t.name === "NameDuplicatedException" ? h.error("模板名称已经存在！") : n.error(t)
        },
        d = function() {
            o.dismiss()
        },
        g = function() {
            i.template.content || (i.template.content = "");
            var n = angular.copy(i.template.content);
            (i.shortMessageSignature && (n = "【" + i.shortMessageSignature + "】" + n), i.formatFields && i.formatFields.length != 0) && (i.formatFields.forEach(function(t) {
                var r = n.indexOf(t.key),
                    i;
                r > -1 && (i = new RegExp(t.key, "g"), n = n.replace(i, t.value))
            }), i.template.type == 1 && (n += "退订回TD"), i.previewText = n)
        },
        y = function() {
            i.formatFields = [{
                key: "【患者姓名】",
                value: "xxx"
            }, {
                key: "【病人姓名】",
                value: "xxx"
            }, {
                key: "【患者称呼】",
                value: "xx"
            }, {
                key: "【预约时间】",
                value: "xxxx年xx月xx日 xx:xx"
            }, {
                key: "【预约医生】",
                value: "xxx"
            }, {
                key: "【ApptTime】",
                value: "xxxx年xx月xx日 xx:xx"
            }, {
                key: "【诊所名称】",
                value: i.officeInfo.name
            }, {
                key: "【诊所地址】",
                value: i.officeInfo.address
            }, {
                key: "【诊所电话】",
                value: i.officeInfo.phoneNumber
            }, ]
        },
        nt = function() {
            var n = t.defer(),
                r = e.officeInfoDic.load().then(function(n) {
                    i.officeInfo = n
                }),
                u = c.getOfficeOption(c.optionKeys.ShortMessageSignature).then(function(n) {
                    if (i.shortMessageSignature = n, !i.shortMessageSignature || i.shortMessageSignature.length == 0) {
                        var t = e.officeDic.getItemSync(l.officeId);
                        t && (i.shortMessageSignature = t.abbreviation)
                    }
                });
            return t.all([r, u]).then(function() {
                n.resolve()
            }), n.promise
        },
        tt = function() {
            y();
            nt().then(function() {
                y();
                i.shortMessageSignature && i.shortMessageSignature.length > 0 && (i.previewText = i.shortMessageSignature)
            })
        };
    (function() {
        i.officeInfo = {};
        i.shortMessageSignature = "";
        i.formatFields = [];
        p();
        i.cancel = d;
        i.save = k;
        i.initTemplate = w;
        i.formatMessageTemplate = g;
        i.previewText = "";
        tt()
    })()
}]);
shortMessageModule.factory("shortMessageTemplateDialogUtil", ["$log", "$q", "$modal", "aresModalShelf", "aresNotification", function(n, t, i, r) {
    "use strict";
    var u = function(n) {
            var t = "",
                i;
            return t = n ? "编辑短信模板" : "创建短信模板", i = r.open({
                template: "<short-message-template-edit-dialog-view><\/short-message-template-edit-dialog-view>",
                controller: "shortMessageTemplateEditDialogCtrl",
                title: t,
                resolve: {
                    host: function() {
                        return {
                            templateId: n
                        }
                    }
                },
                needActive: !0
            }), i.result
        },
        f = function() {
            var n = i.open({
                animation: !0,
                backdrop: "static",
                template: "<short-message-template-category-edit-view><\/short-message-template-category-edit-view>",
                controller: "shortMessageTemplateCategoryEditCtrl",
                windowClass: "short-message-template-category-dialog",
                resolve: {
                    host: function() {
                        return {
                            systemsettingitemId: 0,
                            itemType: "短信大类"
                        }
                    }
                }
            });
            return n.result
        },
        e = function(n) {
            var t = i.open({
                animation: !0,
                backdrop: "static",
                template: "<short-message-template-category-edit-view><\/short-message-template-category-edit-view>",
                controller: "shortMessageTemplateCategoryEditCtrl",
                windowClass: "short-message-template-category-dialog",
                resolve: {
                    host: function() {
                        return {
                            systemsettingitemId: n.id,
                            itemType: "短信大类"
                        }
                    }
                }
            });
            return t.result
        };
    return {
        createShortmessageCategory: f,
        editShortmessageCategory: e,
        editShortmessageTemplateView: u
    }
}]);
shortMessageModule.directive("shortMessageBatchEditView", ["$log", "$timeout", "$window", "aresDialog", function(n, t, i, r) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/short-message/views/short-message-batch-edit-view.html",
        replace: !0,
        link: function(n, u) {
            var o = Ares.kendoGridUtil(i, n),
                f = null,
                s = function() {
                    Ares.validateForm(u.find("#batchForm"), {
                        scheduleTime: {
                            required: !0,
                            dateCn: !0
                        }
                    }, {
                        scheduleTime: {
                            required: "请输入发送日期",
                            dateCn: "请输入合法的日期"
                        }
                    })
                },
                h = function() {
                    var t = [{
                        field: "name",
                        title: "姓名",
                        width: "60px"
                    }, {
                        field: "privateId",
                        title: "病历号",
                        width: "60px"
                    }, {
                        field: "sexStr",
                        title: "性别",
                        width: "40px"
                    }, {
                        field: "ageStr",
                        title: "年龄",
                        width: "40px"
                    }, {
                        field: "mobile",
                        title: "手机",
                        width: "100px"
                    }, {
                        field: "statusStr",
                        title: "发送状态",
                        width: "60px"
                    }, ];
                    return n.$root.isRegularChain && t.splice(1, 0, {
                        field: "officeName",
                        title: "所属诊所",
                        width: "60px"
                    }), n.isViewMode || n.criteria || t.push({
                        template: o.commandTemplate,
                        title: "",
                        width: "30px"
                    }), t
                },
                c = function() {
                    var i, t;
                    n.commands = [{
                        text: "删除",
                        action: "deleteItem",
                        icon: "glyphicon-remove",
                        className: "btn-xs"
                    }];
                    i = h();
                    t = u.find("#patientList");
                    f = t.kendoGrid({
                        dataSource: {
                            data: n.patients || []
                        },
                        height: t.height(),
                        scrollable: !0,
                        sortable: !0,
                        selectable: "single",
                        model: {
                            id: "id"
                        },
                        columns: i
                    }).data("kendoGrid")
                },
                l = function(i, u, f) {
                    t(function() {
                        switch (u) {
                            case "deleteItem":
                                confirm;
                                r.confirm("信息", "您确认要删除吗！").then(function() {
                                    n.delPatient(f)
                                })
                        }
                    })
                },
                e = function() {
                    f ? f.dataSource.data(n.patients) : c()
                },
                a = function(t) {
                    var r = _.find(n.templates, {
                            id: t
                        }),
                        i, u;
                    r && (i = _.find(n.templateTree.dataSource._data, {
                        name: r.category
                    }), i && n.templateTree.expand(n.templateTree.findByUid(i.uid)), u = _.find(i.children._data, {
                        id: t
                    }), n.templateTree.select(n.templateTree.findByUid(u.uid)))
                },
                v = function() {
                    var t = !0;
                    return n.isTemplateInvalid = !n.selectedTemplate, t &= !n.isTemplateInvalid, n.shortMessageBatch.manualSend || (t &= u.find("#batchForm").valid()), t
                };
            (function() {
                n.onCommandClick = l;
                n.selectTemplate = a;
                n.validate = v;
                n.refreshPatientGrid = e;
                s();
                n.$watch("patients", function() {
                    e()
                })
            })();
            t(function() {
                Ares.centerModal(u.closest(".modal-dialog"))
            }, 5)
        }
    }
}]);
shortMessageModule.directive("shortMessageBatchListView", ["$log", "$window", "$timeout", function(n, t, i) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/short-message/views/short-message-batch-list-view.html",
        controller: "ShortMessageBatchListCtrl",
        link: function(n, r) {
            var f = Ares.kendoGridUtil(t, n),
                u = null,
                e = function() {
                    var n = this;
                    n.element.find("table tbody tr").each(function(t, i) {
                        var r = n.dataItem(i),
                            u = $("td.cell-command", i);
                        r.sendTime || r.status >= 1 ? u.find('button[data-action="edit"]').remove() : u.find('button[data-action="view"]').remove()
                    })
                },
                o = function() {
                    var o, s;
                    n.commands = [{
                        text: "查看",
                        action: "view",
                        icon: "glyphicon-eye-open"
                    }, {
                        text: "编辑",
                        action: "edit",
                        icon: "glyphicon-pencil"
                    }];
                    o = $(r).find("#batchList");
                    s = t.innerHeight - 160 - (window.Ares3 ? 30 : 0);
                    u = o.kendoGrid({
                        dataSource: {
                            data: n.batches
                        },
                        scrollable: !1,
                        sortable: !0,
                        selectable: "single",
                        height: s,
                        dataBound: e,
                        change: function() {
                            var t = this.dataItem(this.select());
                            i(function() {
                                n.selectedItem = t ? t : null
                            })
                        },
                        columns: [{
                            field: "creator",
                            title: "创建人",
                            width: "60px",
                            attributes: {
                                "class": "cell-left"
                            }
                        }, {
                            field: "recordCreatedTimeStr",
                            title: "创建时间",
                            width: "60px"
                        }, {
                            field: "shortMessageTemplateName",
                            title: "短信模板",
                            width: "100px"
                        }, {
                            field: "itemCount",
                            title: "群发数量",
                            width: "60px"
                        }, {
                            field: "statusStr",
                            title: "发送状态",
                            width: "60px"
                        }, {
                            field: "sendTimeStr",
                            title: "发送时间",
                            width: "120px"
                        }, {
                            template: f.commandTemplate,
                            title: "",
                            width: "30px",
                            attributes: {
                                "class": "cell-command"
                            }
                        }]
                    }).data("kendoGrid")
                },
                s = function(t, r, u) {
                    i(function() {
                        switch (r) {
                            case "view":
                                n.viewBatch(u);
                                break;
                            case "edit":
                                n.editBatch(u)
                        }
                    })
                },
                h = function() {
                    var i, t, r;
                    u ? (u.dataSource.data(n.batches), n.selectedItem && (i = u.dataSource, t = i.get(n.selectedItem.id), t && (r = u.element.find("tbody>tr[data-uid=" + t.uid + "]"), u.select(r)), n.selectedItem = t)) : o()
                };
            (function() {
                n.onCommandClick = s;
                n.$watch("batches", function() {
                    h()
                })
            })()
        }
    }
}]);
shortMessageModule.directive("shortMessageBatchPatientView", ["$log", "$timeout", "$window", "aresDialog", function(n, t, i) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/short-message/views/short-message-batch-patient-view.html",
        replace: !0,
        link: function(n, r) {
            var e = Ares.kendoGridUtil(i, n),
                u = null,
                o = function() {
                    r.find("#patientList td input[type='checkbox']").each(function() {
                        var i = this,
                            t = $(this).attr("mobile");
                        (t == "null" || t.trim() == "" || t == null) && $(i).attr("disabled", "disabled");
                        $(i).unbind("click").bind("click", function() {
                            var t = parseInt($(this).attr("patientId")),
                                i;
                            this.checked ? n.addPatientIds.indexOf(t) == -1 && n.addPatientIds.push(t) : (i = n.addPatientIds.indexOf(t), i > -1 && n.addPatientIds.splice(i, 1))
                        })
                    });
                    r.find("#patientList th input[type='checkbox']").each(function() {
                        var n = this,
                            t;
                        $(n).attr("title", "全选");
                        t = $(n).attr("name");
                        t == "selectAll" && $(n).unbind("click").bind("click", function() {
                            this.checked ? f(!0) : f(!1)
                        })
                    });
                    r.find("#patientList td button[type='button']").each(function() {
                        var n = this,
                            t = $(n).parents("tr").children().eq(0),
                            i = $(t).children().attr("disabled");
                        $(n).attr("disabled", i)
                    })
                },
                f = function(t) {
                    r.find("#patientList td input[type='checkbox']").each(function() {
                        var i = parseInt($(this).attr("patientId")),
                            r = $(this).attr("mobile"),
                            u;
                        r != "null" && r.trim() != "" && r != null && (this.checked = t);
                        t && (this.checked ? n.addPatientIds.indexOf(i) == -1 && n.addPatientIds.push(i) : (u = n.addPatientIds.indexOf(i), u > -1 && n.addPatientIds.splice(u, 1)))
                    })
                },
                s = function() {
                    return [{
                        title: "&nbsp;&nbsp;&nbsp;<input name='selectAll' id='selectAll' type='checkbox' />",
                        width: "50px",
                        template: "<input  type='checkbox' mobile='#: mobile #' patientId='#: id #'/>"
                    }, {
                        field: "name",
                        title: "姓名"
                    }, {
                        field: "privateId",
                        title: "病历号"
                    }, {
                        field: "sexStr",
                        title: "性别",
                        width: "50px"
                    }, {
                        field: "ageStr",
                        title: "年龄",
                        width: "60px"
                    }, {
                        field: "mobile",
                        title: "手机号码",
                        width: "110px"
                    }, {
                        field: "doctorName",
                        title: "初诊医生"
                    }, {
                        field: "firstVisitStr",
                        title: "初诊日期",
                        width: "100px"
                    }, {
                        field: "sourceType",
                        title: "患者来源"
                    }, {
                        field: "membershipTypeName",
                        title: "会员类型",
                        width: "80px"
                    }, {
                        template: e.commandTemplate,
                        title: "",
                        width: "50px"
                    }]
                },
                h = function() {
                    var i, t;
                    n.commands = [{
                        text: "添加",
                        action: "addPatient",
                        icon: "glyphicon-plus-sign",
                        className: "btn-xs"
                    }];
                    i = s();
                    t = r.find("#patientList");
                    u = t.kendoGrid({
                        dataSource: {
                            data: n.patients
                        },
                        height: t.height(),
                        scrollable: !0,
                        sortable: !0,
                        dataBound: o,
                        selectable: "single",
                        model: {
                            id: "id"
                        },
                        columns: i
                    }).data("kendoGrid")
                },
                c = function(t, i, r) {
                    n.$apply(function() {
                        switch (i) {
                            case "addPatient":
                                n.onAdd(r)
                        }
                    })
                },
                l = function() {
                    u ? (u.dataSource.data(n.patients), t(function() {
                        w()
                    }, 200)) : h()
                },
                k = function(t) {
                    var r = _.find(n.templates, {
                            id: t
                        }),
                        i, u;
                    r && (i = _.find(n.templateTree.dataSource._data, {
                        name: r.category
                    }), i && n.templateTree.expand(n.templateTree.findByUid(i.uid)), u = _.find(i.children._data, {
                        id: t
                    }), n.templateTree.select(n.templateTree.findByUid(u.uid)))
                },
                a = function() {
                    r.find("#apptDoctorDropDown").kendoDropDownList({
                        optionLabel: "--所有--",
                        dataTextField: "name",
                        dataValueField: "id",
                        dataSource: n.Doctors,
                        change: function() {
                            n.isChangeApp = !0
                        }
                    })
                },
                v = function() {
                    r.find("#patientSourceDropDown").kendoDropDownList({
                        optionLabel: "--所有--",
                        dataTextField: "itemName",
                        dataValueField: "itemName",
                        dataSource: n.patientSources,
                        change: function() {
                            n.isChangeApp = !0
                        }
                    })
                },
                y = function() {
                    r.find("#membershipClassDropDown").kendoDropDownList({
                        optionLabel: "--所有--",
                        dataTextField: "name",
                        dataValueField: "id",
                        dataSource: n.membershipClass,
                        change: function() {
                            n.isChangeApp = !0
                        }
                    })
                },
                p = function(t) {
                    r.find("#selectAll")[0].checked = !1;
                    n.pageIndex = t;
                    n.search()
                },
                w = function() {
                    r.find("#patientList td input[type='checkbox']").each(function() {
                        var t = parseInt($(this).attr("patientId"));
                        n.addPatientIds.indexOf(t) > -1 && (this.checked = !0)
                    })
                },
                b = function() {
                    var t = r.find("#patientNameInput").val(),
                        i = r.find("#privateIdInput").val(),
                        o = moment(n.dateRange.startDate).format("YYYY-MM-DD"),
                        s = moment(n.dateRange.endDate).format("YYYY-MM-DD"),
                        u = r.find("#apptDoctorDropDown").val(),
                        f = r.find("#membershipClassDropDown").val(),
                        e = r.find("#patientSourceDropDown").val();
                    return {
                        name: !t ? "" : $.trim(t),
                        privateId: !i ? "" : $.trim(i),
                        pageIndex: n.pageIndex,
                        dateMode: 1,
                        startDate: o,
                        endDate: s,
                        doctorId: !u ? -1 : u,
                        sourceType: !e ? "" : e,
                        membershipTypeId: !f ? -1 : f
                    }
                };
            (function() {
                n.addPatientIds = [];
                n.shortMessageBatchItems = [];
                n.getCriteria = b;
                n.onCommandClick = c;
                n.onPageChanged = p;
                n.$watch("patientSourceDropDownData", function() {
                    n.patientSources && v()
                });
                n.$watch("membershipClass", function() {
                    n.membershipClass && (y(), n.search())
                });
                n.$watch("Doctors", function() {
                    n.Doctors && a()
                });
                n.$watch("patients", function() {
                    n.patients && l()
                })
            })();
            t(function() {
                Ares.centerModal(r.closest(".modal-dialog"))
            }, 5)
        }
    }
}]);
shortMessageModule.directive("shortMessageBillOrderView", ["$log", "$timeout", "$window", "$q", "$modal", "aresDialog", "practiceSvc", "aresNotification", function(n, t, i) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/short-message/views/short-message-bill-order-view.html",
        controller: "shortMessageBillOrderCtrl",
        link: function(n, r) {
            var u = null,
                f = Ares.kendoGridUtil(i, n),
                o = function() {
                    var i, t;
                    n.commands = [{
                        text: "申请开票",
                        action: "applyInvoice",
                        icon: "glyphicon-plus-sign",
                        className: "btn-xs"
                    }];
                    i = s();
                    t = r.find("#billOrderList");
                    r.find("#billOrderList").html("");
                    u = t.kendoGrid({
                        dataSource: {
                            data: n.billOrders
                        },
                        height: t.height() + 30,
                        scrollable: !0,
                        sortable: !0,
                        dataBound: c,
                        selectable: "single",
                        model: {
                            index: "index"
                        },
                        columns: i
                    }).data("kendoGrid")
                },
                s = function() {
                    var t = [],
                        i;
                    return t.splice(0, 0, {
                        title: "<input name='selectAll' id='selectAll' type='checkbox' />",
                        width: "50px",
                        headerAttributes: {
                            style: "text-align: center; font-size: 14px; font-weight: bolder;"
                        },
                        template: "<input  type='checkbox' billOrderStatus='#: billOrderStatus #' index='#: index #'/>"
                    }), n.searchConfig && (i = _.sortBy(n.searchConfig.searchResultFields, "showOrder"), angular.forEach(i, function(n) {
                        t.splice(n.showOrder + 1, 0, h(n.code))
                    })), t.push({
                        template: f.commandTemplate,
                        title: "",
                        width: "50px"
                    }), t
                },
                h = function(n) {
                    var t = {};
                    switch (n) {
                        case "billDate":
                            t = {
                                field: "billDate",
                                title: "日期",
                                format: "{0:yyyy-MM}",
                                width: "150px"
                            };
                            break;
                        case "sendCount":
                            t = {
                                field: "sendCount",
                                title: "发送短信(条)",
                                width: "150px"
                            };
                            break;
                        case "price":
                            t = {
                                field: "price",
                                title: "单价(元)",
                                width: "150px"
                            };
                            break;
                        case "totalPrice":
                            t = {
                                field: "totalPrice",
                                title: "金额(元)",
                                width: "70px"
                            };
                            break;
                        case "billOrderStatusStr":
                            t = {
                                field: "billOrderStatus",
                                title: "账单状态",
                                width: "70px"
                            };
                            break;
                        case "invoiceTypeStr":
                            t = {
                                field: "invoiceType",
                                title: "发票类型",
                                width: "100px"
                            };
                            break;
                        case "applyTime":
                            t = {
                                field: "applyTime",
                                title: "申请开票时间",
                                width: "150px"
                            };
                            break;
                        case "billTime":
                            t = {
                                field: "billTime",
                                title: "开票时间",
                                width: "150px"
                            };
                            break;
                        case "notes":
                            t = {
                                field: "notes",
                                title: "备注",
                                width: "150px"
                            }
                    }
                    return t
                },
                c = function() {
                    r.find("#billOrderList td input[type='checkbox']").each(function(t) {
                        var i = this,
                            r = $(this).attr("billOrderStatus"),
                            t = parseInt($(this).attr("index"));
                        n.addBillOrderIndexs.indexOf(t) > -1 && (i.checked = !0);
                        r == 1 && r || $(i).attr("disabled", "disabled");
                        $(i).unbind("click").bind("click", function() {
                            var t = parseInt($(this).attr("index")),
                                i;
                            this.checked ? n.addBillOrderIndexs.indexOf(t) == -1 && n.addBillOrderIndexs.push(t) : (i = n.addBillOrderIndexs.indexOf(t), i > -1 && n.addBillOrderIndexs.splice(i, 1))
                        })
                    });
                    r.find("#billOrderList th input[type='checkbox']").each(function() {
                        var n = this,
                            t;
                        $(n).attr("title", "全选");
                        t = $(n).attr("name");
                        t == "selectAll" && $(n).unbind("click").bind("click", function() {
                            this.checked ? e(!0) : e(!1)
                        })
                    });
                    r.find("#billOrderList td button[type='button']").each(function() {
                        var n = this,
                            t = $(n).parents("tr").children().eq(0),
                            i = $(t).children().attr("disabled");
                        $(n).attr("disabled", i)
                    })
                },
                e = function(t) {
                    r.find("#billOrderList td input[type='checkbox']").each(function(i) {
                        var i = parseInt($(this).attr("index")),
                            u = $(this).attr("billOrderStatus"),
                            r;
                        u == 1 && u || (this.checked = t);
                        t ? this.checked ? n.addBillOrderIndexs.indexOf(i) == -1 && n.addBillOrderIndexs.push(i) : (r = n.addBillOrderIndexs.indexOf(i), r > -1 && n.addBillOrderIndexs.splice(r, 1)) : n.addBillOrderIndexs = []
                    })
                },
                l = function() {
                    n.initData()
                },
                a = function(t, i, r) {
                    n.$apply(function() {
                        switch (i) {
                            case "applyInvoice":
                                n.applyInvoice(r)
                        }
                    })
                };
            (function() {
                n.addBillOrderIndexs = [];
                n.search = l;
                n.onCommandClick = a;
                n.$watch("billOrders", function() {
                    u ? u.dataSource.data(n.billOrders) : (o(), n.addBillOrderIndexs = [], r.find("#selectAll")[0].checked = !1)
                });
                n.$on("$destroy", function() {
                    f.dispose()
                })
            })();
            t(function() {
                Ares.centerModal(r.closest(".modal-dialog"))
            }, 5)
        }
    }
}]);
shortMessageModule.directive("shortMessageChargeView", ["$log", "$window", "$timeout", "$location", function(n, t, i, r) {
    return {
        restrict: "E",
        templateUrl: "/app/short-message/views/short-message-charge-view.html",
        controller: "ShortMessageChargeCtrl",
        link: function(n, t) {
            var f = function(t) {
                    n.clickCount = t
                },
                u = function(t) {
                    n.selectedPayType = t;
                    t == "Point" ? (n.clickCount = 0, n.btnName = "兑换") : n.btnName = t == "Service" ? "提交" : "充值"
                },
                e = function(r) {
                    var u = n.shortMessageOrders[r];
                    u && (u.isShowNotesInput ? (n.updateOrderNotes(u.id, u.notes), u.isShowNotesInput = !1) : (u.isShowNotesInput = !0, i(function() {
                        t.find("#orderNotes_" + r).focus()
                    }, 5)))
                },
                o = function() {
                    var n = r.search() || {};
                    n.isExchangeCredits && u("Point")
                };
            (function() {
                n.clickCount = 0;
                n.selectedPayType = "";
                n.btnName = "充值";
                n.onClick = f;
                n.onTypeClick = u;
                n.onNotesClicked = e;
                n.isAres3 = window.Ares3;
                o()
            })()
        }
    }
}]);
shortMessageModule.directive("shortMessageConfigView", ["$log", "$timeout", "$q", "aresNotification", "loginContext", "gridOptionUtil", "dataDicSvc", "aresDialog", "enums", "eventAggregator", function(n, t, i, r, u, f, e, o, s) {
    "use strict";
    return {
        restrict: "E",
        controller: "ShortMessageConfigCtrl",
        templateUrl: "/app/short-message/views/short-message-config-view.html",
        link: function(n, r) {
            var h, c, l, u, a = function() {
                    return h = r.find("#events").kendoDropDownList({
                        dataSource: [{
                            name: "会员生日送祝福",
                            value: s.NotificationType.MembershipBirthday
                        }],
                        dataTextField: "name",
                        dataValueField: "value",
                        change: function() {
                            var t = this.value();
                            n.selectedMessageRule.ruleType = t
                        }
                    }).data("kendoDropDownList"), Promise.resolve(!0)
                },
                v = function() {
                    return c = r.find("#selectDay").kendoDropDownList({
                        dataSource: [{
                            name: "会员生日当天",
                            value: s.Frequency2.Daily
                        }],
                        dataTextField: "name",
                        dataValueField: "value",
                        change: function() {
                            var t = this.value();
                            n.selectedMessageRule.freqency = t
                        }
                    }).data("kendoDropDownList"), Promise.resolve(!0)
                },
                y = function() {
                    return l = r.find("#dateTimeSpan").kendoDateTimePicker({
                        interval: 60,
                        timeFormat: "HH:mm",
                        parseFormats: ["HH:mm"],
                        format: "HH:mm",
                        change: function() {
                            var t = moment(this.value()).format("HH:mm");
                            n.selectedMessageRule.startTime = t
                        }
                    }).data("kendoDateTimePicker"), Promise.resolve(!0)
                },
                p = function() {
                    var f = i.defer();
                    return e.shortMessageTemplateDic.load().then(function(i) {
                        var e = i;
                        n.messageTemplate = i;
                        u = r.find("#messageTemplate").kendoDropDownList({
                            optionLabel: "请选择",
                            dataSource: e,
                            dataTextField: "name",
                            dataValueField: "id",
                            change: function() {
                                var u = this.value(),
                                    r;
                                n.selectedMessageRule.templateId = u;
                                r = _.find(i, function(t) {
                                    return t.id == n.selectedMessageRule.templateId
                                });
                                r && (n.selectedMessageRuleContent = r.content);
                                t(function() {
                                    n.$apply()
                                })
                            }
                        }).data("kendoDropDownList");
                        f.resolve()
                    }), f.promise
                },
                b = function() {
                    n.selectedMessageRule.isEnable = !n.selectedMessageRule.isEnable
                },
                k = function() {
                    if (!_.isEmpty(n.copyNotificationRules) && n.selectedMessageRule.id === 0) {
                        var t = _.find(n.copyNotificationRules, function(t) {
                            return t.ruleType == n.selectedMessageRule.ruleType
                        });
                        if (t) return o.warn("提示", "同类型模板请不要重复创建！"), !1
                    }
                    if (n.selectedMessageRule && !n.selectedMessageRule.templateId) return o.warn("提示", "请输入短信模板"), !1;
                    n.selectedMessageRule.dayOffSet = 0;
                    n.saveRule(n.selectedMessageRule)
                },
                w = function(i, r) {
                    if (r) n.selectedMessageRule = angular.copy(i), _.each(n.notificationRules, function(n) {
                        n.selected = !1
                    }), n.selectedMessageRuleContent = "", t(function() {
                        n.$apply()
                    });
                    else {
                        n.isAdd = !1;
                        i.selected = !0;
                        n.selectedMessageRule = angular.copy(i);
                        var f = _.find(n.messageTemplate, function(n) {
                            return i.templateId == n.id
                        });
                        f && (n.selectedMessageRuleContent = f.content)
                    }
                    n.selectedMessageRule && (h.value(n.selectedMessageRule.ruleType), c.value(n.selectedMessageRule.freqency), l.value(n.selectedMessageRule.startTime));
                    n.selectedMessageRule && n.selectedMessageRule.templateId ? u.value(n.selectedMessageRule.templateId) : n.selectedMessageRule && u && u.value("")
                },
                f = function() {
                    var t = n.createNewRuleObj();
                    w(t, !0);
                    n.isAdd = !0
                },
                d = function() {
                    var t = "确认删除【" + n.selectedMessageRule.showName + "】短信触发规则?";
                    o.confirm("确认提示", t).then(function() {
                        n.deleteRule(n.selectedMessageRule.id);
                        f()
                    })
                },
                g = function() {
                    var n = [];
                    return a(), v(), y(), p(), n.push(a, v, y, p), i.all(n)
                };
            (function() {
                n.onSelectedRule = w;
                n.setEnable = b;
                n.onSave = k;
                n.onDelete = d;
                n.onAdd = f;
                g();
                f()
            })()
        }
    }
}]);
shortMessageModule.directive("shortMessageDashboardView", ["$log", "$timeout", "appNav", "reportUtil", function(n, t, i, r) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/short-message/views/short-message-dashboard-view.html",
        controller: "ShortMessageDashboardCtrl",
        link: function(n, t) {
            var i = 600,
                u = 800,
                f = function() {
                    var r = t.find(".chart-block").width(),
                        n = r < i ? i : r;
                    n = n > u ? u : n;
                    t.find("#trendReport").width(n)
                },
                e = function() {
                    f();
                    var i = n.trendData,
                        u = _.max(i, function(n) {
                            return n.totalCnt
                        }),
                        e = u.totalCnt > 8 ? undefined : 1,
                        s = o(i),
                        h = r.generateTrendCategories(i, n.criteria.statMode);
                    r.initLineChart(t.find("#trendReport"), n.title, s, h, e)
                },
                o = function(t) {
                    var i = [];
                    return angular.forEach([{
                        name: "短信发送总数",
                        field: "totalCnt"
                    }, ], function(n) {
                        var r = {
                            name: n.name,
                            data: []
                        };
                        angular.forEach(t, function(t) {
                            r.data.push(t[n.field])
                        });
                        i.push(r)
                    }), n.seriesDataList = i, i
                };
            (function() {
                n.title = "短信发送趋势";
                n.isAres3 = window.Ares3;
                n.$watch("trendData", function() {
                    e()
                })
            })()
        }
    }
}]);
shortMessageModule.directive("shortMessageFeedbackView", ["$log", "$window", "$timeout", "gridOptionUtil", function(n, t, i, r) {
    return {
        restrict: "E",
        templateUrl: "/app/short-message/views/short-message-feedback-view.html",
        controller: "shortMessageFeedbackCtrl",
        link: function(n, u) {
            var o = Ares.kendoGridUtil(t, n),
                f = null,
                s = [{
                    text: "发短信",
                    action: "sendMessage",
                    icon: "glyphicon-comment"
                }],
                e = function() {
                    var e = $(window).height() - 148,
                        t, i;
                    n.commands = s;
                    t = u.find("#shortMessageList");
                    f = t.kendoGrid({
                        dataSource: r.dataSource(h),
                        scrollable: !0,
                        sortable: !0,
                        selectable: "single",
                        pageable: r.pageable,
                        height: e,
                        columns: [{
                            field: "patientName",
                            title: "收信人",
                            width: "60px"
                        }, {
                            field: "mobile",
                            title: "接收号码",
                            width: "80px",
                            attributes: {
                                style: "padding: 0"
                            }
                        }, {
                            field: "sendTimeStr",
                            title: "发送时间",
                            width: "100px",
                            attributes: {
                                style: "padding: 0"
                            }
                        }, {
                            field: "sendContent",
                            title: "短信内容",
                            width: "300px",
                            attributes: {
                                style: "padding: 0"
                            }
                        }, {
                            field: "feedbackTimeStr",
                            title: "回复时间",
                            width: "100px",
                            attributes: {
                                style: "padding: 0"
                            }
                        }, {
                            field: "feedbackContent",
                            title: "回复内容",
                            width: "300px",
                            attributes: {
                                style: "padding: 0"
                            }
                        }, {
                            template: o.commandTemplate,
                            title: "",
                            width: "50px",
                            attributes: {
                                "class": "cell-command"
                            }
                        }]
                    }).data("kendoGrid");
                    i = [{
                        field: "sendTime",
                        dir: "desc"
                    }];
                    f.dataSource.sort(i)
                },
                h = function(t) {
                    n.searchCriteria.pageIndex = t.data.page;
                    n.searchCriteria.pageSize = t.data.pageSize;
                    n.search().then(function(n) {
                        t.success(n)
                    })
                },
                c = function(t, r, u) {
                    i(function() {
                        switch (r) {
                            case "sendMessage":
                                n.send(u)
                        }
                    })
                },
                l = function() {
                    if (f) {
                        var n = u.find(".k-textbox").val() || 1;
                        f.dataSource.page(n)
                    } else e()
                };
            (function() {
                n.onCommandClick = c;
                n.refreshGrid = l;
                e()
            })()
        }
    }
}]);
shortMessageModule.directive("shortMessageHistoryView", ["$log", "$q", "$timeout", "$state", "$window", "enums", "gridOptionUtil", "practiceSvc", "loginContext", "dataDicSvc", function(n, t, i, r, u, f, e, o, s, h) {
    return {
        restrict: "E",
        templateUrl: "/app/short-message/views/short-message-history-view.html",
        scope: {
            officeId: "="
        },
        controller: "ShortMessageHistoryCtrl",
        link: function(n, f) {
            var l = Ares.kendoGridUtil(u, n),
                o = null,
                a = function() {
                    var o = {
                            value: -1,
                            name: "全部"
                        },
                        i, t, u, e;
                    n.statusList.splice(0, 0, o);
                    i = f.find("#statusInput");
                    i.kendoDropDownList({
                        dataSource: n.statusList,
                        placeholder: "",
                        dataTextField: "name",
                        dataValueField: "value",
                        select: function(t) {
                            var i = this.dataItem(t.item.index());
                            n.searchCriteria.status = i.value
                        }
                    });
                    t = i.data("kendoDropDownList");
                    t.value(o.value);
                    r.params.status == "发送失败" && (u = _.find(n.statusList, function(n) {
                        return n.name == "发送失败"
                    }), t.value(u.value), n.searchCriteria.status = u.value);
                    r.params.status == "发送成功" && (e = _.find(n.statusList, function(n) {
                        return n.name == "发送成功"
                    }), t.value(e.value), n.searchCriteria.status = e.value)
                },
                v = function() {
                    y().then(function(t) {
                        var i;
                        t.splice(0, 0, {
                            userID: -2,
                            name: "系统"
                        });
                        i = {
                            id: 0,
                            name: ""
                        };
                        t.splice(0, 0, i);
                        f.find("#sender").kendoDropDownList({
                            dataSource: t,
                            filter: "contains",
                            placeholder: "请选择发送人",
                            dataTextField: "name",
                            dataValueField: "userID",
                            value: null,
                            select: function(t) {
                                var i = this.dataItem(t.item.index());
                                n.searchCriteria.RecordCreatedUser = this.dataItem(t.item)[this.options.dataValueField] || null
                            }
                        })
                    })
                },
                y = function() {
                    var i = t.defer();
                    return h.currentOfficeWorkProviderDic.load().then(function(t) {
                        n.providers = t;
                        i.resolve(t)
                    }), i.promise
                },
                p = function() {
                    $(f).find("#shortMessageList table tbody tr").each(function(n, t) {
                        var i = $("td:nth-child(6)", t);
                        i.addClass("cell-left")
                    })
                },
                s = function() {
                    var t, i, r;
                    n.commands = [{
                        text: "重发",
                        action: "resend",
                        icon: "glyphicon-repeat"
                    }, {
                        text: "发短信",
                        action: "sendMessage",
                        icon: "glyphicon-comment"
                    }, ];
                    t = $(window).height() - 148 - (window.Ares3 ? 30 : 0);
                    isInitialized = !0;
                    i = $(f).find("#shortMessageList");
                    o = i.kendoGrid({
                        dataSource: e.dataSource(w),
                        scrollable: !0,
                        sortable: !0,
                        selectable: "single",
                        dataBound: p,
                        pageable: e.pageable,
                        height: t,
                        columns: [{
                            field: "templateName",
                            title: "类型",
                            width: "60px"
                        }, {
                            field: "patientName",
                            title: "收信人",
                            width: "60px"
                        }, {
                            field: "recordCreatedUser",
                            title: "发送人",
                            width: "60px"
                        }, {
                            field: "mobile",
                            title: "接收号码",
                            width: "80px"
                        }, {
                            field: "sendTimeStr",
                            title: "发送时间",
                            width: "100px"
                        }, {
                            field: "statusStr",
                            title: "发送状态",
                            width: "40px"
                        }, {
                            field: "content",
                            title: "短信内容",
                            width: "300px"
                        }, {
                            template: l.commandTemplate,
                            title: "",
                            width: "50px",
                            attributes: {
                                "class": "cell-command",
                                style: "padding: 0"
                            }
                        }]
                    }).data("kendoGrid");
                    r = [{
                        field: "sendTimeStr",
                        dir: "desc"
                    }];
                    o.dataSource.sort(r)
                },
                w = function(t) {
                    n.searchCriteria.pageIndex = t.data.page;
                    n.searchCriteria.pageSize = t.data.pageSize;
                    n.search().then(function(i) {
                        i.data.length != 0 && angular.forEach(i.data, function(t) {
                            var i = _.find(n.providers, function(n) {
                                return n.userID == t.recordCreatedUser
                            });
                            t.recordCreatedUser = i ? i.name : "系统"
                        });
                        t.success(i)
                    })
                },
                b = function(t, r, u) {
                    i(function() {
                        switch (r) {
                            case "resend":
                                n.resend(u);
                                break;
                            case "sendMessage":
                                n.send(u)
                        }
                    })
                },
                c = function() {
                    var i, r, t, u;
                    o ? (i = f.find(".k-textbox").val() || 1, o.dataSource.page(i), n.selectedItem && (r = o.dataSource, t = r.get(n.selectedItem.id), t && (u = o.element.find("tbody>tr[data-uid=" + t.uid + "]"), o.select(u)), n.selectedItem = t)) : s()
                };
            (function() {
                n.onCommandClick = b;
                n.refreshGrid = c;
                v();
                a();
                s();
                n.minDay = "2018-01-01";
                i(function() {
                    c()
                }, 500)
            })()
        }
    }
}]);
shortMessageModule.directive("shortMessageHomeView", ["$log", "$timeout", "appNav", "practiceSvc", "officeSvc", "moduleOptionProvider", "loginContext", function(n, t, i, r, u, f) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/short-message/views/short-message-home-view.html",
        link: function(n) {
            var t = function() {
                    var t = [new Ares.TabItem("shortMessage.dashboard", "短信一览", "icon-speedometer", "shortMessage.list"), new Ares.TabItem("shortMessage.statistics", "短信统计", "icon-calculator", "shortMessage.statistics"), new Ares.TabItem("shortMessage.history", "短信记录", "icon-notebook", "shortMessage.history"), new Ares.TabItem("shortMessage.batch", "短信群发", "icon-feed", "shortMessage.batch"), new Ares.TabItem("shortMessage.feedback", "短信回复", "icon-bubbles", "shortMessaage.reply"), new Ares.TabItem("shortMessage.charge", "短信充值", "glyphicon glyphicon-usd", "shortMessage.charge"), new Ares.TabItem("shortMessage.config", "短信自动触发规则", "glyphicon glyphicon-cog", "shortMessage.charge"), ];
                    f.isShortmessageTemplateEditEnabled() && t.push(new Ares.TabItem("shortMessage.shortMessageTemplateConfig", "短信模板管理", "glyphicon glyphicon-cog", "shortMessage.shortMessageTemplateConfig"));
                    n.states = t
                },
                r = function() {
                    i.switchState("shortMessage.dashboard", "")
                };
            (function() {
                t()
            })()
        }
    }
}]);
shortMessageModule.directive("shortMessageSearchPatientView", ["$log", "$timeout", "$window", "$q", "$modal", "aresDialog", "practiceSvc", "aresNotification", "dataDicSvc", function(n, t, i, r, u, f, e, o, s) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/short-message/views/short-message-search-patient-view.html",
        replace: !0,
        link: function(n, u) {
            var h = null,
                l = Ares.kendoGridUtil(i, n),
                p = function() {
                    var i, t;
                    n.commands = [{
                        text: "添加",
                        action: "addPatient",
                        icon: "glyphicon-plus-sign",
                        className: "btn-xs"
                    }];
                    i = w();
                    t = u.find("#patientList");
                    u.find("#patientList").html("");
                    h = t.kendoGrid({
                        dataSource: {
                            data: n.searchData.items
                        },
                        height: t.height() + 30,
                        scrollable: !0,
                        sortable: !0,
                        dataBound: k,
                        selectable: "single",
                        model: {
                            id: "id"
                        },
                        columns: i
                    }).data("kendoGrid")
                },
                w = function() {
                    var t, i;
                    return y(), t = [], t.splice(0, 0, {
                        title: "<input name='selectAll' id='selectAll' type='checkbox' />",
                        width: "50px",
                        headerAttributes: {
                            style: "text-align: center; font-size: 14px; font-weight: bolder;"
                        },
                        template: "<input  type='checkbox' mobile='#: mobile #' patientId='#: id #'/>"
                    }), n.searchConfig && (i = _.sortBy(n.searchConfig.searchResultFields, "showOrder"), angular.forEach(i, function(n) {
                        var i = b(n.code);
                        i && t.splice(n.showOrder + 1, 0, i)
                    })), t.push({
                        template: l.commandTemplate,
                        title: "",
                        width: "50px"
                    }), t
                },
                b = function(t) {
                    var i = {},
                        r;
                    switch (t) {
                        case "Name":
                            i = {
                                field: "name",
                                title: "姓名",
                                width: "150px"
                            };
                            break;
                        case "PrivateId":
                            i = {
                                field: "privateId",
                                title: "病历号",
                                width: "150px"
                            };
                            break;
                        case "PatientType":
                            i = {
                                field: "patientType",
                                title: "患者类型",
                                width: "150px"
                            };
                            break;
                        case "Sex":
                            i = {
                                field: "sexStr",
                                title: "性别",
                                width: "70px"
                            };
                            break;
                        case "Age":
                            i = {
                                field: "ageStr",
                                title: "年龄",
                                width: "70px"
                            };
                            break;
                        case "Birth":
                            i = {
                                field: "brithStr",
                                title: "生日",
                                format: "{0:yyyy-MM-dd}",
                                width: "100px"
                            };
                            break;
                        case "Mobile":
                            i = {
                                field: "mobile",
                                title: "手机号码",
                                encoded: !1,
                                attributes: {
                                    "class": "cell-left",
                                    style: "padding: 1px"
                                },
                                width: "150px"
                            };
                            break;
                        case "PhoneNumber":
                            i = {
                                field: "phoneNumber",
                                title: "电话",
                                width: "150px"
                            };
                            break;
                        case "SourceType":
                            i = {
                                field: "sourceType",
                                title: "患者来源",
                                width: "150px"
                            };
                            break;
                        case "FirstVisit":
                            i = {
                                field: "firstVisitStr",
                                title: "初诊日期",
                                format: "{0:yyyy-MM-dd}",
                                width: "100px"
                            };
                            break;
                        case "DoctorName":
                            i = {
                                field: "doctorName",
                                title: "初诊医生",
                                width: "100px"
                            };
                            break;
                        case "LastVisit":
                            i = {
                                field: "lastVisitStr",
                                title: "上次就诊时间",
                                format: "{0:yyyy-MM-dd}",
                                width: "120px"
                            };
                            break;
                        case "LastDoctorName":
                            i = {
                                field: "lastDoctorName",
                                title: "上次就诊医生",
                                width: "120px"
                            };
                            break;
                        case "MembershipType":
                            i = {
                                field: "membershipType",
                                title: "会员类型",
                                width: "150px"
                            };
                            break;
                        case "RecordCreatedTime":
                            i = {
                                field: "recordCreatedStr",
                                title: "创建时间",
                                format: "{0:yyyy-MM-dd}",
                                width: "100px"
                            };
                            break;
                        case "RecordCreatedUserName":
                            i = {
                                field: "recordCreatedUserName",
                                title: "创建人",
                                width: "100px"
                            };
                            break;
                        case "MarketCenterAccount":
                            i = {
                                field: "marketCenterAccountStr",
                                title: "微信绑定",
                                width: "100px"
                            };
                            break;
                        case "Notes":
                            i = {
                                field: "notes",
                                title: "备注",
                                width: "150px"
                            };
                            break;
                        case "TotalAmount":
                            i = {
                                field: "totalAmount",
                                title: "消费总额",
                                width: "150px"
                            };
                            break;
                        case "ConsultantId":
                            i = {
                                field: "consultantName",
                                title: "咨询师",
                                width: "150px"
                            };
                            break;
                        case "Nationality":
                            i = {
                                field: "nationality",
                                title: "国籍",
                                width: "150px"
                            };
                            break;
                        case "PatientTag":
                            i = {
                                field: "patientTag",
                                title: "患者标签",
                                template: l.patientTagTemplate,
                                width: "150px"
                            };
                        case "PrivateTag":
                            i = {
                                field: "privateTag",
                                title: "我的标签",
                                width: "150px"
                            }
                    }
                    return t.indexOf("Field") == 0 && n.patientFreeFields && (r = _.find(n.patientFreeFields, function(n) {
                        return n.fieldCode == t
                    }), r && (i = {
                        field: t.toLowerCase(),
                        title: r.fieldName,
                        width: "150px"
                    })), i
                },
                k = function() {
                    u.find("#patientList td input[type='checkbox']").each(function() {
                        var t = this,
                            i = $(this).attr("mobile"),
                            r = parseInt($(this).attr("patientId"));
                        n.addPatientIds.indexOf(r) > -1 && (t.checked = !0);
                        (i == "null" || i.trim() == "" || i == null) && $(t).attr("disabled", "disabled");
                        $(t).unbind("click").bind("click", function() {
                            var t = parseInt($(this).attr("patientId")),
                                i;
                            this.checked ? n.addPatientIds.indexOf(t) == -1 && n.addPatientIds.push(t) : (i = n.addPatientIds.indexOf(t), i > -1 && n.addPatientIds.splice(i, 1))
                        })
                    });
                    u.find("#patientList th input[type='checkbox']").each(function() {
                        var n = this,
                            t;
                        $(n).attr("title", "全选");
                        t = $(n).attr("name");
                        t == "selectAll" && $(n).unbind("click").bind("click", function() {
                            this.checked ? v(!0) : v(!1)
                        })
                    });
                    u.find("#patientList td button[type='button']").each(function() {
                        var n = this,
                            t = $(n).parents("tr").children().eq(0),
                            i = $(t).children().attr("disabled");
                        $(n).attr("disabled", i)
                    })
                },
                v = function(t) {
                    u.find("#patientList td input[type='checkbox']").each(function() {
                        var i = parseInt($(this).attr("patientId")),
                            r = $(this).attr("mobile"),
                            u;
                        r != "null" && r.trim() != "" && r != null && (this.checked = t);
                        t ? this.checked ? n.addPatientIds.indexOf(i) == -1 && n.addPatientIds.push(i) : (u = n.addPatientIds.indexOf(i), u > -1 && n.addPatientIds.splice(u, 1)) : n.addPatientIds = []
                    })
                },
                a = function(t) {
                    var i = r.defer();
                    return u.find("#searchDropDown").kendoDropDownList({
                        dataTextField: "name",
                        dataValueField: "id",
                        template: '<div class="templateDiv"><table style="width:100%;"><tr><td style="width:150px;"><span>#: data.name #<\/span><\/td><td style="width:25px;"><button type="button" class="btn btn-default btn-xs delBtn" isDisposable="#: data.isDisposable #" isDefault="#: data.isDefault #" searchId="#: data.id #" title="删除"> <span class="glyphicon glyphicon-trash" aria-hidden="true"><\/span><\/button><\/td><td style="width:25px;"><button type="button" class="btn btn-default btn-xs editBtn" isDisposable="#: data.isDisposable #"  searchId="#: data.id #" title="编辑"> <span class="glyphicon glyphicon-pencil" aria-hidden="true"><\/span><\/button><\/td><td><img width="20" height="20" style="cursor:pointer;" code="#: data.name #" isDisposable="#: data.isDisposable #" isPreferred="#: data.isPreferred #" searchId="#: data.id #" src="" title="设为默认搜索条件" /><\/td><\/tr><\/table><\/div>',
                        dataSource: n.searchConfigs,
                        dataBound: d,
                        select: function() {
                            h = null
                        },
                        height: 400
                    }), g(t), i.resolve(!0), i.promise
                },
                y = function() {
                    var t = u.find("#searchDropDown").data("kendoDropDownList");
                    n.searchConfig = _.find(n.searchConfigs, function(n) {
                        return n.name == t.text()
                    })
                },
                c = function(t) {
                    y();
                    n.initData().then(function() {
                        h && !t ? h.dataSource.data(n.searchData.items) : (p(), n.addPatientIds = [], u.find("#selectAll")[0].checked = !1)
                    })
                },
                d = function() {
                    $(".templateDiv img").each(function() {
                        var t = this,
                            r = $(t).attr("isPreferred"),
                            u = $(t).attr("isDisposable"),
                            i = $(t).attr("searchId"),
                            f = $(t).attr("code");
                        u != "true" ? (r == "true" ? $(t).attr("src", "../../../../Content/imgs/xingxing1.png") : $(t).attr("src", "../../../../Content/imgs/xingxing2.png"), $(this).unbind("click").bind("click", function() {
                            (i == 0 || i == "" || i == null) && (i = f == "全部患者" ? -1 : -2);
                            e.updatePreferred(i).success(function(t) {
                                t && n.initSearchConfigs()
                            })
                        })) : $(t).parent().html("")
                    });
                    $(".templateDiv .editBtn").each(function() {
                        var i = this,
                            r = $(i).attr("isDisposable");
                        r != "true" ? $(this).unbind("click").bind("click", function() {
                            var i = $(this).attr("searchId");
                            t(function() {
                                n.openSearchConfigDialog(i)
                            })
                        }) : $(i).parent().html("")
                    });
                    $(".templateDiv .delBtn").each(function() {
                        var t = this,
                            i = $(t).attr("isDefault"),
                            r = $(t).attr("isDisposable");
                        r != "true" ? i == "true" ? $(t).hide() : $(this).unbind("click").bind("click", function() {
                            f.confirm("信息", "确定要删除吗！").then(function() {
                                var i = $(t).attr("searchId");
                                e.deleteSearchConfig(i).success(function(t) {
                                    t && (o.success("删除成功!"), n.searchConfigs = _.filter(n.searchConfigs, function(n) {
                                        return n.id != i
                                    }), a())
                                })
                            })
                        }) : $(t).parent().html("")
                    })
                },
                g = function(t) {
                    var i = null,
                        r;
                    i = _.find(n.searchConfigs, function(n) {
                        return n.isPreferred
                    });
                    t && (i = _.find(n.searchConfigs, function(n) {
                        return n.name == t.name
                    }));
                    i && (r = u.find("#searchDropDown").data("kendoDropDownList"), r.select(function(n) {
                        return n.name === i.name
                    }))
                },
                nt = function(t) {
                    u.find("#selectAll")[0].checked = !1;
                    n.pageIndex = t;
                    c()
                },
                tt = function(t, i, r) {
                    n.$apply(function() {
                        switch (i) {
                            case "addPatient":
                                n.onAdd(r)
                        }
                    })
                },
                it = function() {
                    event.keyCode == 13 && c()
                };
            (function() {
                n.addPatientIds = [];
                n.search = c;
                n.onPageChanged = nt;
                n.onEnter = it;
                n.initSearchConfigDropDown = a;
                n.onCommandClick = tt;
                s.patientFreeFieldConfigDic.loadActive().then(function(t) {
                    n.patientFreeFields = t ? _.sortBy(_.filter(t, function(n) {
                        return n.isInUse
                    }), "seqNum") : null;
                    n.$watch("searchConfigs", function() {
                        n.searchConfigs && n.initialize && a().then(function() {
                            c()
                        })
                    })
                });
                n.$on("$destroy", function() {
                    l.dispose()
                })
            })();
            t(function() {
                Ares.centerModal(u.closest(".modal-dialog"))
            }, 5)
        }
    }
}]);
shortMessageModule.directive("shortMessageStatisticsView", ["$log", "$q", "$timeout", "$state", "$window", "enums", "gridOptionUtil", "practiceSvc", "loginContext", "dataDicSvc", "aresNotification", function(n, t, i, r, u, f, e, o, s, h, c) {
    return {
        restrict: "E",
        templateUrl: "/app/short-message/views/short-message-statistics-view.html",
        scope: {
            officeId: "="
        },
        controller: "ShortMessageStatisticCtrl",
        link: function(n, t) {
            var h = function() {
                    var n = [];
                    return s.isGroup ? n.push({
                        field: "officeName",
                        title: "诊所名称",
                        width: "200px",
                        footerTemplate: "总计"
                    }) : n.push({
                        field: "sendDate",
                        title: "日期",
                        width: "200px",
                        footerTemplate: "总计"
                    }), n.push({
                        field: "sumChargeCount",
                        title: "发送数量",
                        width: "200px",
                        footerTemplate: f("sumSumChargeCount")
                    }), n.push({
                        field: "sucessCount",
                        title: "成功",
                        width: "200px",
                        footerTemplate: f("sumSucessCount")
                    }), n.push({
                        field: "sucessRate",
                        title: "成功率",
                        width: "200px"
                    }), n.push({
                        field: "failCount",
                        title: "失败",
                        width: "200px",
                        footerTemplate: f("sumFailCount")
                    }), n.push({
                        field: "failRate",
                        title: "失败率",
                        width: "200px"
                    }), n.push({
                        field: "unKnownCount",
                        title: "未知",
                        width: "200px",
                        footerTemplate: f("sumUnKnownCount")
                    }), n.push({
                        field: "unKnownRate",
                        title: "未知率",
                        width: "200px"
                    }), n
                },
                o = null,
                e = null,
                r = function(r) {
                    var f = h();
                    n.refreshListData(r).then(function(r) {
                        o = angular.copy(f);
                        i(function() {
                            e = t.find("#shortMessageGrid");
                            e.html("");
                            var i = u.innerHeight - 210 - (window.Ares3 ? 20 : 0),
                                f = e.kendoGrid({
                                    excel: {
                                        allPages: !0
                                    },
                                    dataSource: {
                                        data: r.items
                                    },
                                    height: i,
                                    model: {
                                        id: "id"
                                    },
                                    columns: o,
                                    sortable: !1,
                                    resizable: !0,
                                    reorderable: !0,
                                    columnMenu: !1,
                                    columnMenuInit: function(n) {
                                        n.container.find(".k-sort-asc").remove();
                                        n.container.find(".k-sort-desc").remove();
                                        var t = $(n.container).find(".k-menu-group");
                                        t.find("li").each(function(n, t) {
                                            var i = $(t).text();
                                            i == " " && $(t).remove()
                                        })
                                    }
                                }).data("kendoGrid");
                            n.shortMessageGrid = f
                        })
                    })
                },
                l = function(t) {
                    n.pageIndex = t;
                    r()
                },
                a = function(t) {
                    n.pageSize = t;
                    r()
                },
                v = function() {
                    var t = moment().format("YYYY-MM-DD"),
                        i = t;
                    n.startDate = t;
                    n.endDate = moment(i).add(1, "day").format("YYYY-MM-DD");
                    n.timeSpan = {
                        startDate: t,
                        endDate: i
                    }
                },
                y = function() {
                    v();
                    n.isGroup ? n.selectedOfficeIds = [] : (n.selectedOfficeIds = [s.officeId], r(!1))
                },
                p = function(t) {
                    t = t || n.timeSpan;
                    n.startDate = moment(t.startDate).format("YYYY-MM-DD");
                    n.endDate = moment(t.endDate).add(1, "day").format("YYYY-MM-DD")
                },
                w = function() {
                    var t, i;
                    n.shortMessageGrid && (t = angular.copy(n.shortMessageGrid.columns), n.initSearchCriteria(), i = {
                        criteria: n.searchCriteria,
                        columns: t
                    }, n.exportShortMessage(i))
                },
                b = function() {
                    n.selectedOfficeIds && n.selectedOfficeIds.length > 0 ? r(1) : c.error("请先选择诊所")
                },
                f = function(t) {
                    return function() {
                        var i = 0;
                        return n.pageData && (i = n.pageData.sumInfo[t]), kendo.toString(i)
                    }
                };
            (function() {
                n.onPageChanged = l;
                n.onPageSizeChanged = a;
                n.onDateRangeChanged = p;
                n.search = b;
                n.isGroup = s.isGroup;
                n.exportExcel = w;
                y()
            })()
        }
    }
}]);
shortMessageModule.directive("shortMessageTemplateConfigView", ["$log", "$q", "$timeout", "$filter", "$window", "shortMessageTemplateDialogUtil", "aresDialog", function(n, t, i, r, u, f) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        controller: "ShortMessageTemplateConfigCtrl",
        templateUrl: "/app/short-message/views/short-message-template-config-view.html",
        link: function(n, r) {
            var o = null,
                c = function(n) {
                    var t = '<div class="action-btn"><a href="javascript:void(0)" action="delete"                     template-id="' + n.id + '" class="action-delete">删除<\/a>',
                        i;
                    return t += '<a href="javascript:void(0)" action="edit"                    template-id="' + n.id + '" class="action-edit">修改<\/a>', i = n.isDisabled ? "启用" : "禁用", t += '<a href="javascript:void(0)" action="disable"                    template-id="' + n.id + '" class="action-edit">' + i + "<\/a>", t + "<\/div>"
                },
                l = function() {
                    return [{
                        field: "category",
                        title: "类别",
                        width: "200px",
                        attributes: {
                            "class": "cell-left"
                        }
                    }, {
                        field: "name",
                        title: "名称",
                        width: "80px;"
                    }, {
                        field: "content",
                        title: "内容",
                        width: "300px"
                    }, {
                        field: "shortMessageTypeStr",
                        title: "短信类型",
                        width: "110px"
                    }, {
                        field: "recordCreatedTimeStr",
                        title: "创建时间",
                        width: "110px"
                    }, {
                        title: "操作",
                        width: "150px",
                        template: c
                    }]
                },
                a = function() {
                    r.find("#templateList").on("click", ".action-btn a", function() {
                        var i = $(this),
                            r = i.attr("template-id"),
                            u = i.attr("action"),
                            t = _.find(n.shortmessageTemplates, function(n) {
                                return n.id == r
                            });
                        switch (u) {
                            case "edit":
                                p(t);
                                break;
                            case "delete":
                                n.destroy(t).then(function() {
                                    e()
                                });
                                break;
                            case "disable":
                                n.disableTemplate(t).then(function() {
                                    e()
                                });
                                break;
                            default:
                                return
                        }
                    })
                },
                v = function() {
                    if (n.shortmessageTemplates) {
                        var t = r.find("#templateList");
                        o = t.kendoGrid({
                            dataSource: {
                                data: n.shortmessageTemplates
                            },
                            sortable: !0,
                            change: function() {
                                var t = this.dataItem(this.select());
                                i(function() {
                                    n.selectedItem = t ? t : null
                                })
                            },
                            columns: l(),
                            dataBound: a()
                        }).data("kendoGrid")
                    }
                },
                e = function() {
                    var i = t.defer();
                    return o ? n.load().then(function() {
                        var u, t, f;
                        o.dataSource.data(n.shortmessageTemplates);
                        n.selectedItem && (u = o.dataSource, t = u.get(n.selectedItem.id), t && (f = r.find("#templateList").find("tbody>tr[data-uid=" + t.uid + "]"), o.select(f)), n.selectedItem = t);
                        i.resolve()
                    }) : (v(), i.resolve()), i.promise
                },
                y = function() {
                    f.editShortmessageTemplateView().then(function() {
                        e()
                    })
                },
                p = function(n) {
                    f.editShortmessageTemplateView(n.id).then(function() {
                        e()
                    })
                },
                w = function() {
                    f.createShortmessageCategory().then(function() {
                        n.initCategoryList().then(function() {
                            s()
                        })
                    })
                },
                b = function(t, i) {
                    f.editShortmessageCategory(t).then(function() {
                        n.initCategoryList().then(function() {
                            s()
                        })
                    });
                    i.stopPropagation()
                },
                k = function() {
                    var n = angular.element(u).height() - 95,
                        t = n - 110,
                        i = r.find("#templateList");
                    i.height(t)
                },
                d = function(t) {
                    n.initBaseInfo();
                    n.initCategoryList().then(function() {
                        n.templateCategories && n.templateCategories.length > 0 && h(n.templateCategories[0]);
                        n.load().then(function() {
                            t && o && (o.destroy(), o = null, r.find("#templateList").empty());
                            k();
                            e(t)
                        })
                    })
                },
                g = function(n, t) {
                    n.isHover = t
                },
                s = function() {
                    n.selectedCategory ? (angular.forEach(n.templateCategories, function(t) {
                        t.id != n.selectedCategory.id ? t.isClicked = !1 : (t.isClicked = !0, n.selectedCategory = angular.copy(t))
                    }), n.criteria.category = n.selectedCategory.isClicked ? n.selectedCategory.itemName : "", e()) : e()
                },
                h = function(t) {
                    t.isClicked = !t.isClicked;
                    angular.forEach(n.templateCategories, function(n) {
                        n.itemName != t.itemName && (n.isClicked = !1)
                    });
                    n.criteria.category = t.isClicked ? t.itemName : "";
                    n.selectedCategory = t.isClicked ? angular.copy(t) : null;
                    e()
                };
            (function() {
                n.refreshGrid = e;
                n.addHandle = y;
                n.createShortmessageCategory = w;
                n.editShortmessageCategory = b;
                n.onHover = g;
                n.onClicked = h;
                d()
            })()
        }
    }
}]);